Beispiel #1
0
        static void Main(string[] args)
        {
            BSTree tree = new BSTree(new List <int> {
                0, 1, 2, 3, 4, 9, 8, 7, 6, 5
            });

            Console.Write("Enter a command: [I]nsert, [D]elete, [S]earch, [F]ind minimum");
            string input = Console.ReadLine();

            if (input == "I")
            {
                Console.Write("What number do you want to insert: ");
                int _input = Int32.Parse(Console.ReadLine());
                tree.insert(_input);
            }
            else if (input == "D")
            {
                Console.Write("What number do you want to delete: ");
                int _input = Int32.Parse(Console.ReadLine());
                tree.delete(_input);
            }
            else if (input == "S")
            {
                Console.Write("What number do you want to delete: ");
                int _input = Console.Read();
                Console.Write(tree.Search(_input));
            }
            else
            {
                Console.Write(tree.FindMinimum());
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            // Create a new binary tree
            BSTree bt = new BSTree();

            // Insert data
            bt.insert(11);
            bt.insert(3);
            bt.insert(54);
            bt.insert(6);
            bt.insert(42);
            bt.insert(95);
            bt.insert(2);
            bt.insert(45);
            bt.insert(24);
            bt.insert(23);
            bt.insert(34);

            Node parent = bt.findParent(45);

            Console.WriteLine(parent == null ? "Parent could not be found." : parent.value.ToString());

            Console.Read();
        }