Beispiel #1
0
        LinkListNH <int> CreateListTail()
        {
            Node <int>       R = new Node <int>();       //Temp Ptr R是L.Head是L->next
            int              d;
            LinkListNH <int> L = new LinkListNH <int>(); //L是新生成的链表引用

            R = L.Head;
            d = Int32.Parse(Console.ReadLine());
            while (d != -1)
            {
                Node <int> p = new Node <int>(d);
                if (L.Head == null)
                {   //空表
                    L.Head = p;
                }
                else
                {   //head->next = p
                    R.Next = p;
                }
                R = p;
                d = Int32.Parse(Console.ReadLine());
            }
            if (R != null)
            {   //set the tail
                R.Next = null;
            }
            return(L);
        }
Beispiel #2
0
        LinkListNH <int> CreateLListHead_DeadCirle_HandData_HandEnd()
        {
            int d;
            LinkListNH <int> L = new LinkListNH <int>();//L是新生成的链表引用

            d = Int32.Parse(Console.ReadLine());
            while (d != -1)
            {                                     //-1是输入数据的结束标志
                Node <int> p = new Node <int>(d); //p是新插入的结点
                p.Next = L.Head;                  //L.Head是Node1
                L.Head = p;                       //Clan mean: L.head = >L.next
                d      = Int32.Parse(Console.ReadLine());
            }
            return(L);
        }
Beispiel #3
0
        LinkListNH <int> CreateLListHead_HandData_HandCount()
        {   //在头部插入结点建立单链表的算法
            int count;
            int val;
            LinkListNH <int> L = new LinkListNH <int>();

            Console.WriteLine("input count:");
            count = Int32.Parse(Console.ReadLine());
            Console.WriteLine("input val:");
            val = Int32.Parse(Console.ReadLine());

            while (count != 0)
            {
                Node <int> p = new Node <int>(val);
                p.Next = L.Head; //头插法 core
                L.Head = p;      //头插法 core
                count--;
            }
            return(L);
        }