예제 #1
0
        private static student enterStudent()
        {
            int TNumber;
            string Name;
            string Advisor;
            student tmpStudent;

            Console.WriteLine("\n\nCreate a new Student record:");
            Console.Write("\nEnter a TNumber: ");
            TNumber = int.Parse(Console.ReadLine());
            Console.Write("Enter Student Name: ");
            Name = Console.ReadLine();
            Console.Write("Enter Advisor Name: ");
            Advisor = Console.ReadLine();
            tmpStudent = new student(TNumber, Name, Advisor);
            Console.Clear();
            return tmpStudent;
        }
예제 #2
0
        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();
        }
예제 #3
0
 public Node Insert(Node node, student data)
 {
     if (node == null)               //BST is empty
         node = new Node(data);
     else
     {
         if (data.TNumber <= node.data.TNumber)
             node.left = Insert(node.left, data);    // new node goes somewhere in left subtree
         else
             node.right = Insert(node.right, data);  // new node goes into the right subtree
     }
     return node;
 }
예제 #4
0
파일: Node.cs 프로젝트: CJonesTSU/COMP3040
 public Node(student d)
 {
     data = d;
     left = null;
     right = null;
 }
예제 #5
0
 public void Insert(student data)
 {
     root = Insert(root, data);
 }