Exemple #1
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"));
        }