Beispiel #1
0
        static void Main(string[] args)
        {
            int p1  = 20;
            int p2  = 15;
            int p3  = 30;
            int p4  = 25;
            int p5  = 35;
            int p6  = 22;
            int p7  = 28;
            int p8  = 32;
            int p9  = 38;
            int p10 = 31;
            int p11 = 33;

            BinaryTree bt = new BinaryTree();

            bt.Add(p1);
            bt.Add(p2);
            bt.Add(p3);
            bt.Add(p4);
            bt.Add(p5);
            bt.Add(p6);
            bt.Add(p7);
            bt.Add(p8);
            bt.Add(p9);
            bt.Add(p10);
            bt.Add(p11);

            bt.Remove(16);

            //Console.WriteLine(bt.counter);

            //BinaryTreeItem bt1 = new BinaryTreeItem();

            //bt1 = bt.FindRecursiv(23);
            //bt1 = bt.FindItemBeforeItemToFind(20);

            //bt1 = bt.FindMaxRecursiv(3);
            //bt1 = bt.FindMinRecursiv(3);



            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            BinaryTree tree = new BinaryTree();
            string     result;

            do
            {
                Console.WriteLine("1. Insert");
                Console.WriteLine("2. Search");
                Console.WriteLine("3. Remove");
                Console.WriteLine("4. Print");
                Console.WriteLine("5. PreOrderPrint");
                Console.WriteLine("6. InOrderPrint");
                Console.WriteLine("7. PostOrderPrint");
                Console.WriteLine("8. Exit");
                result = Console.ReadLine();

                if (result == "1")
                {
                    Console.WriteLine("what do you want to insert?");
                    char inserted = char.Parse(Console.ReadLine());
                    tree.Insert(inserted);
                    Console.WriteLine();
                }

                if (result == "2")
                {
                    Console.WriteLine("What letter do you want to search for?");
                    char Searched = char.Parse(Console.ReadLine());
                    if (tree.Search(Searched) == false)
                    {
                        Console.WriteLine("Sorry, the letter doesn't exist.");
                        Console.WriteLine();
                    }

                    if (tree.Search(Searched) == true)
                    {
                        Console.WriteLine("Yay, " + Searched + " exists!");
                        Console.WriteLine();
                    }
                    tree.Search(Searched);
                }

                if (result == "3")
                {
                    Console.WriteLine("What letter do you want to remove?");
                    tree.Remove(char.Parse(Console.ReadLine()));
                    Console.WriteLine();
                }

                if (result == "4")
                {
                    tree.Print();
                }

                if (result == "5")
                {
                    tree.PreOrderPrint();
                    Console.WriteLine();
                    Console.WriteLine();
                }

                if (result == "6")
                {
                    tree.InOrderPrint();
                    Console.WriteLine();
                    Console.WriteLine();
                }

                if (result == "7")
                {
                    tree.PostOrderPrint();
                    Console.WriteLine();
                    Console.WriteLine();
                }
            } while (result != "8");
        }