static void interact() { BinarySearchTree BST = new BinarySearchTree(); ConsoleKeyInfo cki; int num; student tempStudent; do { Console.WriteLine(); Console.WriteLine("Press the Escape (Esc) to return to this testing type menu\n"); Console.WriteLine("1: Insert Student value"); Console.WriteLine("2: Delete Student value"); Console.WriteLine("3: Search "); Console.WriteLine(""); Console.Write("\nEnter your choice: "); cki = Console.ReadKey(); switch (cki.Key) { case ConsoleKey.D1: case ConsoleKey.NumPad1: tempStudent = enterStudent(); BST.Insert(tempStudent); break; case ConsoleKey.D2: case ConsoleKey.NumPad2: Console.Write("\nEnter an TNumber to delete: "); num = int.Parse(Console.ReadLine()); BST.Delete(num); break; case ConsoleKey.D3: case ConsoleKey.NumPad3: Console.Write("\nEnter an TNumber to search: "); num = int.Parse(Console.ReadLine()); Node found = BST.Search(num); if (found != null) Console.Write("\nData found: " + "TNumber: " + found.data.TNumber + " Name: " + found.data.Name + " Advisor: " + found.data.Advisor); else Console.WriteLine("\nNo data found"); break; } Console.WriteLine("\nContents of BST : "); BST.Display(); } while (cki.Key != ConsoleKey.Escape); }
static void staticData() { ConsoleKeyInfo cki; BinarySearchTree BST = new BinarySearchTree(); student tempStudent; Console.Clear(); Console.WriteLine("Remove element from empty tree."); BST.Delete(1); Console.WriteLine("\nContents of BST : "); BST.Display(); Console.WriteLine("\n\nAdd an student to empty tree."); tempStudent = new student(50, "Student One", "Sekmen"); BST.Insert(tempStudent); Console.WriteLine("\nContents of BST : "); BST.Display(); Console.WriteLine("\n\nAdd a student on each side of the root."); tempStudent = new student(75, "Student Two", "Al Nasr"); BST.Insert(tempStudent); tempStudent = new student(25, "Student Three", "Chen"); BST.Insert(tempStudent); Console.WriteLine("\nContents of BST : "); BST.Display(); Console.WriteLine("\n\nAdd several students on each side of the root."); // put some students on left of root tempStudent = new student(15, "Student Four", "Al Nasr"); // left of root.left BST.Insert(tempStudent); tempStudent = new student(10, "Student Five", "Chen"); // left of root.left.left BST.Insert(tempStudent); tempStudent = new student(12, "Student Six", "Al Nasr"); // right of root.left.left BST.Insert(tempStudent); tempStudent = new student(11, "Student Seven", "Chen"); // left of root.left.left.right BST.Insert(tempStudent); tempStudent = new student(13, "Student Seven", "Chen"); // right of root.left.left.right BST.Insert(tempStudent); // some on the right tempStudent = new student(60, "Student Eight", "Al Nasr"); // left of root.right BST.Insert(tempStudent); tempStudent = new student(78, "Student Nine", "Chen"); // right of root.right BST.Insert(tempStudent); tempStudent = new student(79, "Student Ten", "Al Nasr"); // right of root.right.right BST.Insert(tempStudent); tempStudent = new student(74, "Student Eleven", "Chen"); // left of root.right BST.Insert(tempStudent); Console.WriteLine("\nContents of BST : "); BST.Display(); //Delete the children of root Console.WriteLine("\nDelete root.left"); BST.Delete(25); Console.WriteLine("Delete root.right"); BST.Delete(75); Console.WriteLine("\nContents of BST : "); BST.Display(); //Delete the root Console.WriteLine("\nDelete root"); BST.Delete(50); Console.WriteLine("\nContents of BST : "); BST.Display(); //Delete the rest Console.WriteLine("\nDelete remaining content in randomish order"); BST.Delete(78); BST.Delete(10); BST.Delete(11); BST.Delete(60); BST.Delete(79); BST.Delete(12); BST.Delete(13); BST.Delete(15); BST.Delete(74); Console.WriteLine("\nContents of BST : "); BST.Display(); //hold up so we can print this off... Console.WriteLine("\n\nPress any key to return to main menu."); cki = Console.ReadKey(); Console.Clear(); }