static void Main(string[] args) { BinarySearchTree nums = new BinarySearchTree(); nums.Add(50); nums.Add(17); nums.Add(23); nums.Add(7); nums.Add(1); nums.Add(72); nums.Add(76); nums.Add(12); nums.Add(62); nums.Display(); Console.WriteLine(); Console.WriteLine("50 " + nums.Find(50)); Console.WriteLine("76 " + nums.Find(76)); Console.WriteLine("7 " + nums.Find(7)); Console.WriteLine("10 " + nums.Find(10)); Console.WriteLine("100 " + nums.Find(100)); Console.ReadKey(); }
static void Main(string[] args) { BinarySearchTree <int> binarySearchTree = new BinarySearchTree <int>(56); binarySearchTree.Insert(30); binarySearchTree.Insert(70); binarySearchTree.Display(); Console.WriteLine("-----------------------"); binarySearchTree.Insert(40); binarySearchTree.Insert(22); binarySearchTree.Insert(11); binarySearchTree.Insert(3); binarySearchTree.Insert(16); binarySearchTree.Insert(60); binarySearchTree.Insert(95); binarySearchTree.Insert(65); binarySearchTree.Insert(63); binarySearchTree.Insert(67); binarySearchTree.Display(); Console.WriteLine("------------------------"); binarySearchTree.IfExists(67, binarySearchTree); }
static void Main(string[] args) { BinarySearchTree tree = new BinarySearchTree(); tree.AddNode(10); tree.AddNode(8); tree.AddNode(3); tree.AddNode(7); tree.AddNode(1); tree.AddNode(4); tree.AddNode(5); tree.AddNode(2); tree.AddNode(9); tree.AddNode(6); tree.Display(); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine(" Welcome to binary search tree!"); BinarySearchTree <int> binarySearchTree = new BinarySearchTree <int>(); binarySearchTree.InsertData(56); binarySearchTree.InsertData(30); binarySearchTree.InsertData(70); binarySearchTree.InsertData(22); binarySearchTree.InsertData(40); binarySearchTree.InsertData(11); binarySearchTree.InsertData(3); binarySearchTree.InsertData(16); binarySearchTree.InsertData(60); binarySearchTree.InsertData(95); binarySearchTree.InsertData(65); binarySearchTree.InsertData(63); binarySearchTree.InsertData(67); binarySearchTree.Display(binarySearchTree.GetRoot()); Console.WriteLine("Count of elements in Binary search tree is: " + binarySearchTree.GetSize()); }
static void Main(string[] args) { Console.WriteLine("Welcome to the Binary Search Tree Program"); BinarySearchTree <int> bst = new BinarySearchTree <int>(56); bst.Insert(56); bst.Insert(30); bst.Insert(70); bst.Insert(22); bst.Insert(40); bst.Insert(60); bst.Insert(95); bst.Insert(11); bst.Insert(65); bst.Insert(3); bst.Insert(16); bst.Insert(63); bst.Insert(67); bst.Display(); bst.GetSize(); bst.IfExists(100, bst); }
static void Main(string[] args) { BinarySearchTree binarySearchTree = new BinarySearchTree(); //Adds data to the binary tree binarySearchTree.Insert(56); binarySearchTree.Insert(30); binarySearchTree.Insert(70); binarySearchTree.Insert(22); binarySearchTree.Insert(40); binarySearchTree.Insert(11); binarySearchTree.Insert(3); binarySearchTree.Insert(16); binarySearchTree.Insert(60); binarySearchTree.Insert(95); binarySearchTree.Insert(65); binarySearchTree.Insert(63); binarySearchTree.Insert(67); binarySearchTree.Display(); Console.WriteLine("size of binary search tree is : " + binarySearchTree.Size()); Console.WriteLine("element " + binarySearchTree.Search(63) + " found in binary search tree"); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); BinarySearchTree <int> binarySearch = new BinarySearchTree <int>(56); binarySearch.Insert(30); binarySearch.Insert(70); binarySearch.Insert(22); binarySearch.Insert(40); binarySearch.Insert(60); binarySearch.Insert(95); binarySearch.Insert(11); binarySearch.Insert(65); binarySearch.Insert(3); binarySearch.Insert(16); binarySearch.Insert(63); binarySearch.Insert(67); binarySearch.Display(); bool result = binarySearch.IfExists(67, binarySearch); Console.WriteLine(result); Console.ReadKey(); }
static void Main(string[] args) { Console.WriteLine("Binary Search Tree:"); BinarySearchTree tree = new BinarySearchTree(); tree.Add(60); tree.Add(50); tree.Add(70); tree.Add(30); tree.Add(35); tree.Add(10); tree.Add(5); tree.Display(); Console.WriteLine("Pre-order: "); tree.PreOrder(); Console.WriteLine(); Console.WriteLine("Post-order: "); tree.PostOrder(); Console.WriteLine(); Console.WriteLine("Level order: "); tree.LevelOrder(); Console.WriteLine(); int input = 15; Console.WriteLine($"Searching tree for {input}..."); BinarySearchTree.Search(input, tree.root); input = 30; Console.WriteLine($"Searching tree for {input}..."); BinarySearchTree.Search(input, tree.root); Console.ReadLine(); }
static void Main(string[] args) { BinarySearchTree bt = new BinarySearchTree(); int choice, x; while (true) { WriteLine(); WriteLine("1. Display Tree"); WriteLine("2. Search"); WriteLine("3. Add a New Node"); WriteLine("4. Delete a Node"); WriteLine("5. Preorder Traversal"); WriteLine("6. Inorder Traversal"); WriteLine("7. Postorder Traversal"); WriteLine("8. Height of Tree"); WriteLine("9. Find Minimum Key"); WriteLine("10. Find Maximum Key"); WriteLine("11. Quit"); Write("Please enter your selection: "); choice = Convert.ToInt32(ReadLine()); WriteLine(); if (choice == 11) { break; } switch (choice) { case 1: bt.Display(); break; case 2: Write("Enter the key to be searched: "); x = Convert.ToInt32(ReadLine()); if (bt.Search(x)) { WriteLine("Key found."); } else { WriteLine("Key not found."); } break; case 3: Write("Enter the key to be inserted: "); x = Convert.ToInt32(ReadLine()); bt.Insert(x); break; case 4: Write("Enter the key to be deleted: "); x = Convert.ToInt32(ReadLine()); bt.Delete(x); break; case 5: bt.Preorder(); break; case 6: bt.Inorder(); break; case 7: bt.Postorder(); break; case 8: WriteLine($"Height of tree is {bt.Height()}"); break; case 9: WriteLine($"Minimum key is {bt.Min()}"); break; case 10: WriteLine($"Maximum key is {bt.Max()}"); break; default: WriteLine("Please make a valid selection."); break; } } }
static void Main(string[] args) { var bt = new BinarySearchTree(); int x; while (true) { Console.WriteLine("1. Display tree"); Console.WriteLine("2. Search"); Console.WriteLine("3. Insert a new node"); Console.WriteLine("4. Delete a node"); Console.WriteLine("5. PreOrder Traversal"); Console.WriteLine("6. InOrder Traversal"); Console.WriteLine("7. PostOrder Traversal"); Console.WriteLine("8. Height of tree"); Console.WriteLine("9. Find Minimum key"); Console.WriteLine("10. Find Maximum key"); Console.WriteLine("11. Quit"); var choice = Convert.ToInt32(Console.ReadLine()); if (choice == 11) { break; } switch (choice) { case 1: bt.Display(); break; case 2: Console.Write("Enter a key to be searched : "); x = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(bt.Search(x) ? "Key was found" : "Key not found"); break; case 3: Console.Write("Enter a key to be Inserted : "); x = Convert.ToInt32(Console.ReadLine()); bt.Insert(x); break; case 4: Console.Write("Enter a key to be Deleted : "); x = Convert.ToInt32(Console.ReadLine()); bt.Delete(x); break; case 5: bt.PreOrder(); break; case 6: bt.InOrder(); break; case 7: bt.PostOrder(); break; case 8: Console.WriteLine($"The HEIGHT of the tree is : {bt.Height()}"); break; case 9: Console.WriteLine($"The MINIMUM key is : {bt.Min()}"); break; case 10: Console.WriteLine($"The MAXIMUM key is : {bt.Max()}"); break; default: Console.WriteLine("Invalid selection entered!!!"); break; } } }
static void Main(string[] args) { BinarySearchTree bt = new BinarySearchTree(); int choice, x; while (true) { Console.WriteLine("1.Display Tree"); Console.WriteLine("2.Search"); Console.WriteLine("3.Insert a new node"); Console.WriteLine("4.Delete a node"); Console.WriteLine("5.Preorder Traversal"); Console.WriteLine("6.Inorder Traversal"); Console.WriteLine("7.Postorder Traversal"); Console.WriteLine("8.Height of tree"); Console.WriteLine("9.Find Minimum key"); Console.WriteLine("10.Find Maximum key"); Console.WriteLine("11.Quit"); Console.Write("Enter your choice:"); choice = Convert.ToInt32(Console.ReadLine()); if (choice == 11) { break; } switch (choice) { case 1: bt.Display(); break; case 2: Console.Write("Enter the key to be searched:"); x = Convert.ToInt32(Console.ReadLine()); if (bt.Search(x)) { Console.WriteLine("Key found"); } else { Console.WriteLine("key not found"); } break; case 3: Console.Write("Enter the key to be inserted:"); x = Convert.ToInt32(Console.ReadLine()); bt.Insert(x); break; case 4: Console.Write("Enter the key to be deleted:"); x = Convert.ToInt32(Console.ReadLine()); bt.Delete(x); break; case 5: bt.PreOrder(); break; case 6: bt.InOrder(); break; case 7: bt.PostOrder(); break; case 8: Console.WriteLine("Height of tree is " + bt.Height()); break; case 9: Console.WriteLine("Minimum key is " + bt.Min()); break; case 10: Console.WriteLine("Maximum key is " + bt.Max()); break; } } }