Esempio n. 1
0
        static void Main(string[] args)
        {
            Random random = new Random();
            BinarySearchTree <int> tree  = new BinarySearchTree <int>();
            List <Node <int> >     nodes = new List <Node <int> >();

            tree.AddNode(new Node <int>(38));
            tree.AddNode(new Node <int>(38));
            tree.AddNode(new Node <int>(30));
            tree.AddNode(new Node <int>(38));
            //for (int i = 0; i < 100; i++)
            //{
            //    Node<int> node = new Node<int>(random.Next(1, 100));
            //    nodes.Add(node);
            //}
            //foreach (Node<int> node in nodes)
            //{
            //    tree.AddNode(node);
            //}
            tree.Display();
            Console.WriteLine(tree.Search(25));
            Console.ReadLine();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            BinarySearchTree binaryTree = new BinarySearchTree();

            binaryTree.Add(9);
            binaryTree.Add(6);
            binaryTree.Add(2);
            binaryTree.Add(4);
            binaryTree.Add(5);
            binaryTree.Add(3);

            Console.WriteLine("Tree is:");
            binaryTree.Display();
            Console.WriteLine("\nCount = " + binaryTree.Count);
            Console.WriteLine("\nAdd 99");
            binaryTree.Add(99);
            Console.WriteLine("\nCount = " + binaryTree.Count);
            Console.WriteLine("Search for 9 " + binaryTree.Search(9));
            Console.WriteLine("Search for 3 " + binaryTree.Search(3));
            Console.WriteLine("Search for 7 " + binaryTree.Search(7));


            Console.ReadLine();
        }