示例#1
0
        static void Main(string[] args)
        {
            BinaryTree binaryTree = new BinaryTree();

            binaryTree.InsertNode(75);
            binaryTree.InsertNode(42);
            binaryTree.InsertNode(32);
            binaryTree.InsertNode(67);
            binaryTree.InsertNode(54);
            binaryTree.InsertNode(32);
            Console.WriteLine(binaryTree.SearchTree(67));
            Console.ReadLine();
        }
示例#2
0
        static void Main(string[] args)
        {
            BinaryTree treeNode = new BinaryTree();

            treeNode.Add(100);
            treeNode.Add(99);
            treeNode.Add(101);
            treeNode.Add(55);
            treeNode.Add(130);
            treeNode.Add(120);
            treeNode.Add(75);

            treeNode.SearchTree();
            Console.ReadLine();
        }
示例#3
0
        static double[] TestTree(int n, double[] nums)
        {
            var rand = new Random();


            var tree = new BinaryTree(nums);

            double[] times = new double[2];
            int      index = rand.Next(0, n - 1);
            //index = n - 1;
            var timer = new System.Diagnostics.Stopwatch();

            timer.Start();
            tree.SearchTree(nums[index]);
            timer.Stop();
            //Console.WriteLine("Binary Tree Search: {0} ticks", timer.ElapsedTicks);
            times[0] = timer.ElapsedTicks;
            timer.Restart();
            LinearSearch(nums, nums[index]);
            timer.Stop();
            //Console.WriteLine("Linear Search: {0} ticks", timer.ElapsedTicks);
            times[1] = timer.ElapsedTicks;
            return(times);
        }
示例#4
0
 //The Search method takes a tree and a value and calls the SearchTree method with the value
 public static bool Search(BinaryTree tree, int value)
 {
     return(tree.SearchTree(value));
 }