public static void Init() { // A // / \ // / \ // B --> C // / \ /\ // b1->D-> E-> F // / \ // G -------->H Node A = new Node('A'); Node B = new Node('B'); Node B1 = new Node('1'); Node C = new Node('C'); Node D = new Node('D'); Node E = new Node('E'); Node F = new Node('F'); Node G = new Node('G'); Node H = new Node('H'); A.Left = B; A.Right = C; B.Left = B1; B.Right = D; C.Left = E; C.Right = F; //PreOrder Traversal - Works for complete binary trees Console.WriteLine("Print populated Tree using PreOrder Traversal:"); A.ConnectUsingPreOrder(A); A.PrintTree(); //Add leaf nodes. Now tree is not a complete binary tree. D.Left = G; F.Right = H; //Using Dictionary Console.WriteLine(""); Console.WriteLine("Print populated Tree using using Dictionary:"); A.ConnectUsingDictionary(); A.PrintTree(); //Using Queue Console.WriteLine(""); Console.WriteLine("Print populated Tree using Queue:"); A.connectUsingQueue(); A.PrintTree(); ///* Constructed binary tree is // 10 // / \ // 8 2 // / \ // 3 90 //*/ //Node root = new Node(10); //root.Left = new Node(8); //root.Right = new Node(2); //root.Left.Left = new Node(3); //root.Right.Right = new Node(90); //// Populates Next pointer in all nodes //root.connectUsingQueue(); //// Let us check the values of nextRight pointers //Console.WriteLine(""); //Console.WriteLine("Following are populated nextRight pointers in \n" + "the tree (-1 is printed if there is no nextRight)"); //Console.WriteLine("Next of " + root.Data + " is " + ((root.Next != null) ? root.Next.Data : -1)); //Console.WriteLine("Next of " + root.Left.Data + " is " + ((root.Left.Next != null) ? root.Left.Next.Data : -1)); //Console.WriteLine("Next of " + root.Right.Data + " is " + ((root.Right.Next != null) ? root.Right.Next.Data : -1)); //Console.WriteLine("Next of " + root.Left.Left.Data + " is " + ((root.Left.Left.Next != null) ? root.Left.Left.Next.Data : -1)); //Console.WriteLine("Next of " + root.Right.Right.Data + " is " + ((root.Right.Right.Next != null) ? root.Right.Right.Next.Data : -1)); }