static void Main(string[] args) { /*Node<int> tree = new Node<int>(6); * tree.Left = new Node<int>(2); * tree.Left.Right = new Node<int>(5);*/ Node <int>[] a = { new Node <int>(5), new Node <int>(10), new Node <int>(20) }; a[0].Left = a[1]; a[0].Right = a[2]; //a[1].Left = a[3]; string hold = ""; BinTree <int> tree = new BinTree <int>(a[0]); tree.PreOrder(ref hold); Console.WriteLine("Pre-Order = " + hold); string hold2 = ""; tree.InOrder(ref hold2); Console.WriteLine("In Order = " + hold2); string hold3 = ""; tree.PostOrder(ref hold3); Console.WriteLine("Post Order = " + hold3); Console.Read(); }
static void Main(string[] args) { Node <string> root = new Node <string>("A"); BinTree <string> tree = new BinTree <string>(root); root.Left = new Node <string>("B"); root.Right = new Node <string>("C"); root.Left.Left = new Node <string>("D"); root.Left.Right = new Node <string>("E"); root.Right.Left = new Node <string>("F"); root.Right.Right = new Node <string>("G"); root.Left.Right.Right = new Node <string>("H"); string inOrd = ""; string preOrd = ""; string posOrd = ""; tree.InOrder(ref inOrd); Console.WriteLine("InOrder: " + inOrd); tree.PreOrder(ref preOrd); Console.WriteLine("PreOrder: " + preOrd); tree.PostOrder(ref posOrd); Console.WriteLine("PostOrder: " + posOrd); Node <string> root2 = new Node <string>("Z"); BinTree <string> tree2 = new BinTree <string>(root2); root2.Left = new Node <string>("Y"); root2.Right = new Node <string>("X"); root2.Left.Left = new Node <string>("W"); root2.Left.Right = new Node <string>("V"); root2.Right.Left = new Node <string>("U"); root2.Right.Right = new Node <string>("T"); string tree2inOrd = ""; tree2.InOrder(ref tree2inOrd); Console.WriteLine("\nTree2 InOrder: " + tree2inOrd); Console.WriteLine("\nCopying Tree2 to Tree:"); tree.Copy(tree2); string copyTreeInOrd = ""; tree.InOrder(ref copyTreeInOrd); Console.WriteLine("\ncopyTree InOrder: " + copyTreeInOrd); Console.WriteLine("\nNumber of items in tree: " + tree.Count(tree)); Console.ReadKey(); }