コード例 #1
0
        static void Main(string[] args)
        {
            BinaryTree sample = new BinaryTree();

            sample.Add(5);
            sample.Add(6);
            sample.Add(7);
            sample.Search(7);
            sample.Search(8);
            Console.ReadLine();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            BinaryTree tree = new BinaryTree();

            tree.Add(10);
            tree.Add(7);
            tree.Add(3);
            tree.Add(20);
            tree.Add(27);
            tree.Search(1);
            tree.Search(3);
            tree.Search(33);
            tree.Search(27);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: nararamim/projeto_AED2
        public static void Main(string[] args)
        {
            BinaryTree b = new BinaryTree();

            b.Insert(1, "repos1.txt");
            b.Insert(6, "repos2.txt");
            b.Insert(2, "repos3.txt");
            b.Insert(4, "repos4.txt");
            b.Insert(5, "repos5.txt");
            b.Insert(3, "repos6.txt");
            b.Insert(798, "repos7.txt");
            b.Insert(998, "repos8.txt");
            b.Insert(0, "repos9.txt");
            b.Insert(75, "repos10.txt");
            b.Insert(56, "repos11.txt");
            b.Insert(98790, "repos12.txt");

            b.Display();

            Console.WriteLine("Insert requested element:");
            int element = int.Parse(Console.ReadLine());

            string result = b.Search(element);

            Console.WriteLine("The repository of the requested element is:");
            Console.WriteLine(result);

            Console.ReadLine();
        }
コード例 #4
0
        static void Main(string[] args)
        {
            BinaryTree <int> binaryTree = new BinaryTree <int>();
            Random           ran        = new Random();

            for (int i = 0; i < 50; i++)
            {
                int random = ran.Next(100);
                binaryTree.AddLeaf(random);
            }

            int        search = ran.Next(100);
            Leaf <int> found  = binaryTree.Search(search);

            if (found != null)
            {
                Console.WriteLine(search + " found");
            }
            else
            {
                Console.WriteLine(search + " not found");
            }

            Console.ReadLine();
        }
コード例 #5
0
        static void Main(string[] args)
        {
            BinaryTree Tree = new BinaryTree();

            Tree.Add(100);
            Tree.Add(120);
            Tree.Add(50);
            Tree.Add(45);
            Tree.Add(46);
            Tree.Add(88);
            Tree.Add(119);
            Tree.Add(310);
            Tree.Search(45);
            Tree.Search(120);
            Console.ReadLine();
        }
コード例 #6
0
        static void Main(string[] args)
        {
            Stopwatch stopwatch = new Stopwatch();

            int[]            numberArray = new int[200000];
            Random           rand        = new Random();
            BinaryTree <int> newTree     = new BinaryTree <int>();

            Console.WriteLine("Generating Tree...");
            stopwatch.Start();
            for (int i = 0; i < 200000; i++)
            {
                Node <int> insertNode = new Node <int>();
                insertNode.value = rand.Next(5001);
                newTree.InsertValue(insertNode);
            }
            stopwatch.Stop();
            Console.WriteLine("Time Elapsed in creation {0} milliseconds", stopwatch.ElapsedMilliseconds);
            stopwatch.Reset();
            stopwatch.Start();
            // Searchable value
            Node <int> searchObject = newTree.Search(3231);

            stopwatch.Stop();
            Console.WriteLine("Value {0} found in {1} milliseconds", searchObject.value, stopwatch.ElapsedMilliseconds);
            Console.ReadLine();
        }
コード例 #7
0
        static void Main(string[] args)
        {
            BinaryTree tree = new BinaryTree();

            tree.RootInsert(13);
            tree.RootInsert(80);
            tree.RootInsert(101);
            tree.RootInsert(1);
            tree.RootInsert(55);
            tree.RootInsert(23);
            tree.RootInsert(72);

            tree.Search(101);
            tree.Search(5);

            tree.Display();

            Console.ReadLine();
        }
コード例 #8
0
        static void Main(string[] args)
        {
            BinaryTree tree = new BinaryTree();

            tree.Add();
            tree.Add();
            tree.Add();
            tree.Add();
            tree.Add();
            tree.Search();
        }
コード例 #9
0
        static void Main(string[] args)
        {
            BinaryTree myTree = new BinaryTree();

            myTree.addItem(50);
            myTree.addItem(60);
            myTree.addItem(15);
            myTree.addItem(45);
            myTree.addItem(86);
            myTree.addItem(65);
            myTree.Search(45);
            Console.ReadLine();
        }
コード例 #10
0
ファイル: Driver.cs プロジェクト: ClassicHat/DataStructures
        static void Main(string[] args)
        {
            //Create a Tree
            BinaryTree theTree = new BinaryTree();

            //Arraylist full of letters
            char[] letters = new char[10] {
                'J', 'F', 'D', 'A', 'G', 'C', 'H', 'B', 'I', 'E'
            };

            for (int i = 0; i < 10; i++)
            {
                theTree.Insert(letters[i]);
            }

            theTree.Traverse();

            theTree.Search('H');

            theTree.Search('Z');

            ReadKey();
        }
コード例 #11
0
        static void Main(string[] args)
        {
            BinaryTree classmatesAge = new BinaryTree();

            classmatesAge.AddData(28);
            classmatesAge.AddData(25);
            classmatesAge.AddData(22);
            classmatesAge.AddData(21);
            classmatesAge.AddData(27);
            classmatesAge.AddData(24);
            classmatesAge.AddData(99);
            classmatesAge.AddData(19);

            classmatesAge.Search(19);
        }
コード例 #12
0
ファイル: Program.cs プロジェクト: Reinharta/BinarySearchTree
        static void Main(string[] args)
        {
            BinaryTree newTree = new BinaryTree();

            newTree.Add(4);
            newTree.Add(2);
            newTree.Add(1);
            newTree.Add(6);
            newTree.Add(5);
            newTree.Add(4);
            bool findValue = newTree.Search(3);

            Console.WriteLine(findValue);
            Console.ReadKey();
        }
コード例 #13
0
        static void Main(string[] args)
        {
            Console.WriteLine("Binary Search Tree");

            var tree = new BinaryTree <int>();

            tree.InsertNode(new Node <int>(50));
            tree.InsertNode(new Node <int>(25));
            tree.InsertNode(new Node <int>(10));
            tree.InsertNode(new Node <int>(5));
            tree.InsertNode(new Node <int>(75));
            tree.InsertNode(new Node <int>(100));
            tree.InsertNode(new Node <int>(60));

            Console.WriteLine("Pre Order");
            tree.PreOrderTraversal(x => Console.WriteLine(x.ToString()));
            Console.WriteLine();
            Console.WriteLine("In Order");
            tree.InOrderTraversal(x => Console.Write($" {x} -->"));
            Console.WriteLine();
            Console.WriteLine("Post Order");
            tree.PostOrderTraversal(x => Console.Write($" {x} -->"));

            var searchNumber = 50;

            Console.WriteLine();
            Console.WriteLine($"Found: {searchNumber} {tree.Search(searchNumber,out var node)} {node}");

            searchNumber = 5;
            Console.WriteLine();
            Console.WriteLine($"Found: {searchNumber} {tree.Search(searchNumber, out node)} {node}");

            searchNumber = 100;
            Console.WriteLine();
            Console.WriteLine($"Found: {searchNumber} {tree.Search(searchNumber, out node)} {node}");
        }
コード例 #14
0
        static void Main(string[] args)
        {
            BinaryTree tree = new BinaryTree();

            tree.Add(6);
            tree.Add(7);
            tree.Add(5);
            tree.Add(4);
            tree.Add(9);


            tree.Search(4);

            Console.ReadLine();
        }
コード例 #15
0
        static void Main(string[] args)
        {
            BinaryTree tree = new BinaryTree();

            tree.Add(50);
            tree.Add(100);
            tree.Add(25);
            tree.Add(35);
            tree.Add(45);
            tree.Add(95);
            tree.Add(65);
            tree.Add(75);
            Console.WriteLine(tree.Search(25));
            Console.ReadLine();
        }
コード例 #16
0
        static void Main(string[] args)
        {
            BinaryTree tree = new BinaryTree();

            tree.Add(100);
            tree.Add(110);
            tree.Add(90);
            tree.Add(120);
            tree.Add(85);
            tree.Add(150);
            tree.Add(130);
            tree.Add(70);
            tree.Add(95);
            tree.Add(70);
            tree.Search(85);
        }
コード例 #17
0
        static void Main(string[] args)
        {
            BinaryTree binaryTree = new BinaryTree();

            binaryTree.Add(100);
            binaryTree.Add(94);
            binaryTree.Add(133);
            binaryTree.Add(120);
            binaryTree.Add(88);
            binaryTree.Add(99);
            binaryTree.Add(84);
            binaryTree.Add(55);
            binaryTree.Add(70);
            binaryTree.Search(70);
            Console.ReadLine();
        }
コード例 #18
0
        static void Main(string[] args)
        {
            BinaryTree bTree = new BinaryTree();


            bTree.Insert(1);
            bTree.Insert(6);
            bTree.Insert(2);
            bTree.Insert(4);
            bTree.Insert(5);
            bTree.Insert(3);

            bTree.Display();
            bTree.Search(1);

            Console.ReadLine();
        }
コード例 #19
0
        static void Main(string[] args)
        {
            BinaryTree <int> tree = new BinaryTree <int>(56);

            tree.Insert(70);
            tree.Insert(30);
            tree.Insert(40);
            tree.Insert(22);
            tree.Insert(11);
            tree.Insert(16);
            tree.Insert(3);
            tree.Insert(60);
            tree.Insert(95);
            tree.Insert(65);
            tree.Insert(63);
            tree.Insert(67);
            tree.Search(63);
            Console.ReadLine();
        }
コード例 #20
0
ファイル: Program.cs プロジェクト: aquasius/BinaryTree
        static void Main(string[] args)
        {
            BinaryTree BST = new BinaryTree();

            BST.Add(30);
            BST.Add(12);
            BST.Add(47);
            BST.Add(66);
            BST.Add(28);
            BST.Add(10);
            BST.Add(59);
            BST.Add(41);
            BST.Add(60);


            bool result = BST.Search(24);

            Console.WriteLine(result);
            Console.ReadLine();
        }
コード例 #21
0
        static void Main(string[] args)
        {
            BinaryTree theTree = new BinaryTree();

            theTree.Insert(23);
            theTree.Insert(43);
            theTree.Insert(12);
            theTree.Insert(54);
            theTree.Insert(22);
            theTree.Insert(76);
            theTree.Insert(54);
            theTree.Insert(34);
            Console.WriteLine("Inorder Traversal : ");
            theTree.InorderTransveral(theTree.ReturnRoot());
            Console.WriteLine(" ");

            //Checks each node of the tree and outputs if node is present or not
            //using Search()
            Console.WriteLine(" ");
            theTree.Search(theTree.root, 2);
            Console.ReadKey();
        }
コード例 #22
0
        static void Main(string[] args)
        {
            ///creating head node by parameterised constructor
            BinaryTree <int> binaryTree = new BinaryTree <int>(56);

            binaryTree.Insert(30);
            binaryTree.Insert(70);
            binaryTree.Insert(22);
            binaryTree.Insert(40);
            binaryTree.Insert(11);
            binaryTree.Insert(18);
            binaryTree.Insert(3);
            binaryTree.Insert(60);
            binaryTree.Insert(95);
            binaryTree.Insert(65);
            binaryTree.Insert(63);
            binaryTree.Insert(67);
            ///Displaying binary tree
            binaryTree.Display();
            binaryTree.GetSize();
            binaryTree.Search(63);
        }
コード例 #23
0
ファイル: Program.cs プロジェクト: MTorres4/BinarySearchTree
        static void Main(string[] args)
        {
            BinaryTree Tree1 = new BinaryTree();

            Tree1.Add(14);
            Tree1.Add(7);
            Tree1.Add(22);
            Tree1.Add(9);
            Tree1.Add(12);

            bool SearchTree = Tree1.Search(12);

            if (SearchTree)
            {
                Console.WriteLine("Found");
            }

            else
            {
                Console.WriteLine("Not Found");
            }

            Console.ReadLine();
        }