Example #1
0
        public void AddLast(int data)
        {
            DoubleNode newnode = new DoubleNode(data);

            tail.next        = newnode;
            newnode.previous = tail;
            tail             = newnode;
        }
Example #2
0
 public void DeleteLast()
 {
     if (head.next == null)
     {
         throw new Exception("List is empty");
     }
     tail      = tail.previous;
     tail.next = null;
 }
Example #3
0
        public void TraverseForward()
        {
            DoubleNode node = head;

            while (node.next != null)
            {
                node = node.next;
                Console.WriteLine(node.data);
            }
        }
Example #4
0
        public void TraverseBackward()
        {
            DoubleNode node = tail;

            while (node != head)
            {
                Console.WriteLine(node.data);
                node = node.previous;
            }
        }
Example #5
0
 public void DeleteFirst()
 {
     if (head.next != null)
     {
         if (head.next == tail)
         {
             tail = head;
         }
         head.next = head.next.next;
     }
 }
Example #6
0
        public void AddFirst(int data)
        {
            DoubleNode newnode = new DoubleNode(data);

            if (head.next == null)
            {
                newnode.previous = tail;
                tail.next        = newnode;
                tail             = newnode;
            }
            else
            {
                newnode.next          = head.next;
                newnode.next.previous = newnode;
                newnode.previous      = head;
                head.next             = newnode;
            }
        }
Example #7
0
 public DoublyLinkedList()
 {
     head = new DoubleNode();
     tail = head;
 }