static void Main(string[] args)
        {
            Tree tree = new Tree();

            Random random = new Random();

            for (int i = 0; i < 10; i++)
            {
                tree.AddValue(random.Next(0, 100));
            }

            Console.WriteLine("Binary tree in sorted order\n");
            tree.Traverse();

            int  j      = 7; //hardcoded value to search on binary tree
            Node result = tree.Search(j);

            Console.WriteLine($"\nsearching for {j} in binary tree");

            if (result == null)
            {
                Console.WriteLine("not found");
            }
            else
            {
                Console.WriteLine($"found object: {result} with {result.value}");
            }

            Console.ReadLine();
        }
Exemple #2
0
        public static void Test1()
        {
            Console.WriteLine("Starting the Test !!");
            Console.ReadLine();

            Console.WriteLine(">> Initialising values");
            int[] TestValue = Utilities.RandomFiller.RandomInt32Array();
            Tree<int> TestTree = new Tree<int>();
            Random rand_0 = new Random();

            for(int i = 0; i < 10; i++){
                Console.WriteLine(">>>> Adding value number {0}", i);
                TestTree.AddValue(TestValue[rand_0.Next(0, 100)]);
            }

            Console.WriteLine();
            Console.WriteLine(">>Starting the Test when enter is pressed");
            Console.ReadLine();

            for (int i = 0; i < 100; i++) {
                Console.WriteLine(">>>> Searching for {0} >> ", i);
                Console.Write(TestTree.GetValue(i));
            }

            Console.WriteLine();
            Console.WriteLine("Done with Test1 !!");
            Console.WriteLine("Press enter to exit");
            Console.ReadLine();
        }