Exemplo n.º 1
0
        public static void Do()
        {
            DoublyLinkedList list = new DoublyLinkedList();
            DLnode           node = new DLnode();

            node.Data = "root";
            list.Add(node);
            for (int i = 0; i < 10; i++)
            {
                DLnode nodeInLoop = new DLnode();
                nodeInLoop.Data = i.ToString();
                list.Add(nodeInLoop);
            }

            Console.WriteLine("Length of double linked list is - {0}", list.GetLength());

            Console.WriteLine("Traversing forward...\n");
            DLnode nodeToRead = list.GetRoot();

            while (nodeToRead != null)
            {
                Console.WriteLine(nodeToRead.Data);
                nodeToRead = list.GetNext();
            }

            Console.WriteLine("Traversing backwards...");
            nodeToRead = list.GetPrev();
            while (nodeToRead != null)
            {
                Console.WriteLine(nodeToRead.Data);
                nodeToRead = list.GetPrev();
            }
        }
Exemplo n.º 2
0
 public DLnode GetNext()
 {
     if (Current.Next is null)
     {
         return(null);
     }
     else
     {
         Current = Current.Next;
         return(Current);
     }
 }
Exemplo n.º 3
0
 public DLnode GetPrev()
 {
     if (Current.Prev is null)
     {
         return(null);
     }
     else
     {
         Current = Current.Prev;
         return(Current);
     }
 }
Exemplo n.º 4
0
 public void Add(DLnode node)
 {
     node.Next = null;
     if (root == null)
     {
         root      = node;
         Length    = 1;
         Current   = root;
         root.Prev = null;
     }
     else
     {
         Current.Next = node;
         node.Prev    = Current;
         Current      = node;
         Length++;
     }
 }
Exemplo n.º 5
0
 public DLnode GetRoot()
 {
     Current = root;
     return(this.root);
 }