예제 #1
0
        static void Main(string[] args)
        {
            // 1
            Console.WriteLine("1. List Node");
            Console.WriteLine("InsertAfter, InsertBefore\n");
            DListNode list = new DListNode(30);

            list.InsertAfter(50);
            list.InsertAfter(40);
            list.InsertBefore(10);
            list.InsertBefore(20);
            ResultNodeList(list);

            // 2
            Console.WriteLine("\n///////////////////////////////////////////////");
            Console.WriteLine("\n2. Linked List");
            Console.WriteLine("Append, Prepend, RemoveHead, RemoveTail\n");
            DLinkList linklist = new DLinkList();

            linklist.Append(30);
            linklist.Append(40);
            linklist.Append(50);
            linklist.Prepend(20);
            linklist.Prepend(10);
            Console.WriteLine("Head is " + linklist.m_head.m_data + " and Tail is " + linklist.m_tail.m_data + "\n");
            linklist.RemoveHead();
            linklist.RemoveTail();
            ResultNodeLinkList(linklist);
            CheckNullonRemoveNode(linklist);

            // 3
            Console.WriteLine("\n///////////////////////////////////////////////");
            Console.WriteLine("\n3. Iterators");
            Console.WriteLine("Insert, Remove\n");
            Console.WriteLine("The List Contains\n");
            DListIterator itr  = linklist.GetIterator();
            DListNode     node = linklist.m_head;

            linklist.Insert(itr, 25);
            linklist.Remove(itr, node);

            ResultIterator(itr);

            Console.ReadLine();
        }
예제 #2
0
 public void Prepend(int p_data)
 {
     if (m_tail == null)
     {
         m_tail = m_head = new DListNode(p_data);
     }
     else
     {
         m_head.InsertBefore(p_data);
         m_head = m_head.m_previous;
     }
     m_count++;
 }