/// <summary>
        /// Build BST instantiates a new BinarySearchTree, and adds nodes accordingly (in order), then console Logs an AddNode, and two Searches.
        /// </summary>
        public static void BuildBST()
        {
            BinarySearchTree BST = new BinarySearchTree(new Node(100));

            BST.AddNode(75, BST.Root);
            BST.AddNode(90, BST.Root);
            BST.AddNode(120, BST.Root);
            // This method returns the node, so we are going to check the value of the return
            Console.WriteLine(BST.AddNode(150, BST.Root).Value);
            Console.WriteLine("^ his add should be : 150 +++");
            // this method returns null if it doesn't exist, and the node if it does.
            if (BST.Search(BST.Root, 69) == null)
            {
                Console.WriteLine("This Console.WriteLine should appear if searching a non-existing node returns null");
            }
            Console.WriteLine(BST.Search(BST.Root, 90).Value);
            Console.WriteLine("^ This Search should return 90 ++++");
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var minHeapTree = new HeapTree();
            var bstTree     = new BinarySearchTree();

            List <int> items = new List <int> {
                48, 22, 33, 45, 67, 231, 90, 0, 12, 77
            };

            items.ForEach(item => {
                minHeapTree.AddNode(item);
                bstTree.AddNode(item);
            });
            Console.WriteLine("Print Binary Search Tree (TraversalTree Begin):");
            var result = TraversalTree(bstTree.Root);

            foreach (var line in result)
            {
                Console.WriteLine(string.Join(",", line));
            }

            Console.WriteLine("Print Binary Search Tree (TraversalTree End).");

            Console.WriteLine(string.Join(",", minHeapTree.Items));

            minHeapTree.PopNode();

            Console.WriteLine(string.Join(",", minHeapTree.Items));

            minHeapTree.AddNode(2);

            Console.WriteLine(string.Join(",", minHeapTree.Items));

            Console.WriteLine("Print Binary Search Tree (In Order):");
            bstTree.InOrderTraversal(bstTree.Root);

            Console.WriteLine("Print Binary Search Tree (Pre Order):");
            bstTree.PreOrderTraversal(bstTree.Root);

            Console.WriteLine("Print Binary Search Tree (Post Order):");
            bstTree.PostOrderTraversal(bstTree.Root);

            string[] dictionary = new string[] { "robert", "rober", "roberthan", "rob", "pig", "dock" };
            var      trieTree   = new TrieTree();

            foreach (var s in dictionary)
            {
                trieTree.Add(s);
            }
            Console.WriteLine("Print Trie Tree:");
            Console.WriteLine(trieTree.FindCount("robe"));
        }