Example #1
0
 private DllNode FindLastNode(DllNode node)
 {
     if (node.next != null)
     {
         return(FindLastNode(node.next));
     }
     else
     {
         return(node);
     }
 }
Example #2
0
        internal void Print(DllNode node)
        {
            if (node == null)
            {
                Console.WriteLine(" Done.");
                return;
            }

            Console.Write(node.item + " ");
            Print(node.next);
        }
Example #3
0
 public void AddNode(DllNode node)
 {
     if (root == null)
     {
         root = node;
     }
     else
     {
         var lastNode = FindLastNode(root);
         lastNode.next = node;
         node.prev     = lastNode;
     }
 }
Example #4
0
        public void ConvertBTreeToDllInorder(Node node, DoubleLinkedList dllTree)
        {
            if (node == null)
            {
                return;
            }

            ConvertBTreeToDllInorder(node.left, dllTree);  // first recursively convert left subtree

            var dllNode = new DllNode(node.item);

            dllTree.AddNode(dllNode);

            ConvertBTreeToDllInorder(node.right, dllTree);  // now recur on right child
        }
Example #5
0
 public DllNode(int item)
 {
     this.item = item;
     prev      = null;
     next      = null;
 }