static void Main(string[] args) { try { ObjectPersistence persister = new ObjectPersistence(); const string TreeStoreFile = @"D:\SavedTree.bin"; #region Construct the tree Console.WriteLine("Constructing tree...\t"); BST bst = new BST(); bst.Insert(20); bst.Insert(25); bst.Insert(45); bst.Insert(15); bst.Insert(67); bst.Insert(43); bst.Insert(80); bst.Insert(33); bst.Insert(67); bst.Insert(99); bst.Insert(91); #endregion #region Traverse the tree Console.WriteLine(@"---------------------------------------------------- Before serialization and de-serialization"); Console.WriteLine("\nInorder Traversal (Left - Root - Right):"); bst.Inorder(bst.GetRoot()); Console.WriteLine("\nPreorder Traversal (Root - Left - Right): "); bst.Preorder(bst.GetRoot()); Console.WriteLine("\nPostorder Traversal (Left - Right - Root): "); bst.Postorder(bst.GetRoot()); #endregion #region Serialize and de-serialize the tree to and from a file Console.WriteLine(@" ---------------------------------------------------- Storing (serializing) tree to file..."); persister.StoreBSTToFile(bst, TreeStoreFile); Console.WriteLine(string.Format("Tree saved to {0} in binary format\nDe-serializing in process...\t", TreeStoreFile)); bst = persister.ReadBSTFromFile(TreeStoreFile); Console.WriteLine("\nAfter serialization and de-serialization"); Console.WriteLine("\nInorder Traversal (Left - Root - Right):"); bst.Inorder(bst.GetRoot()); Console.WriteLine("\nPreorder Traversal (Root - Left - Right): "); bst.Preorder(bst.GetRoot()); Console.WriteLine("\nPostorder Traversal (Left - Right - Root): "); bst.Postorder(bst.GetRoot()); #endregion #region Finding maximum, minimum and size of BST Console.WriteLine(@" ---------------------------------------------------- Other details of the tree"); Console.WriteLine("Minimum value in the tree: " + bst.GetMinimum(bst.GetRoot())); Console.WriteLine("Maximum value in the tree: " + bst.GetMaximum(bst.GetRoot())); Console.WriteLine("Size of the tree: " + bst.GetSize(bst.GetRoot())); #endregion } catch (Exception ex) { Console.WriteLine("Oops!\n" + ex.Message); } //Keep the console running Console.WriteLine("\nPRESS ENTER TO TERMINATE..."); Console.ReadLine(); }