链表不是这么写的http://www.shrinkrays.net/code-snippets/csharp/linked-list-and-double-linked-lists-in-csharp.aspx

解决方案 »

  1.   

    caozhy你的网址很有用!多谢,多谢!
      

  2.   

    这样就不会重复了,在你的基础上稍做了一些修改。using System;
    using System.Collections.Generic;
    using System.Text;
    //程序主要功能是用随机数生成两个链表,并输出 
    namespace test2
    {
    class count
    {
    public int number;
    public count next;
    }
    class Program
    {
    static void Main(string[] args)
    {
    czMath cz = new czMath();
    count head1 = new count();
    count head2 = new count();
    cz.add(ref head1);
    count current1 = head1;
    while (current1 != null)
    {
    Console.Write("\0\0{0}", current1.number);
    current1 = current1.next;
    }
    Console.WriteLine();
    cz.add(ref head2);
    count current2 = head2;
    while (current2 != null)
    {
    Console.Write("\0\0{0}", current2.number);
    current2 = current2.next;
    }
    Console.WriteLine();
    Console.ReadLine();
    }
    } class czMath
    {
    static int GetRandomSeed()
    {
    byte[] bytes = new byte[4];
    System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
    rng.GetBytes(bytes);
    return BitConverter.ToInt32(bytes, 0);
    } public void add(ref count head)
    {
    count current;
    count temp;
    Random ran = new Random(GetRandomSeed());
    current = head;
    current.number = ran.Next(100);
    current.next = null;
    for (int i = 0; i <= 5; i++)
    {
    temp = new count();
    temp.number = ran.Next(100);
    temp.next = null;
    current.next = temp;
    current = current.next;
    }
    }
    }
    }