Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            AvlTree <int> tree = new AvlTree <int>();

            tree.Add(30);
            tree.Add(91);
            tree.Add(19);
            tree.Add(76);
            tree.Add(40);
            tree.Add(71);
            tree.Add(8);
            tree.Add(99);
            tree.Add(90);
            tree.Add(21);

            tree.Remove(21);
            tree.Remove(30);
            tree.Remove(99);
            tree.Remove(71);
            tree.Remove(40);
            tree.Remove(8);
            tree.Remove(91);
            tree.Remove(19);
            tree.Remove(76);
            tree.Remove(90);
        }
Ejemplo n.º 2
0
        static void Main()
        {
            var tree = new AvlTree <int>();

            tree.Add(5);
            tree.Add(8);
            tree.Add(10);
            tree.ForeachDfs((depth, val) =>
            {
                Console.WriteLine("{0}{1}", new string('-', depth), val);
            });
        }
        static void Main(string[] args)
        {
            //http://stackoverflow.com/questions/3955680/how-to-check-if-my-avl-tree-implementation-is-correct

            var arrtest = new int[] { 1, 5, 7, 4, 8, 2, 6 };

            var arr15a = new int[] { 20, 4, 15 };
            var arr15b = new int[] { 20, 4, 26, 3, 9, 15 };
            var arr15c = new int[] { 20, 4, 26, 3, 21, 9, 30, 2, 7, 11, 15 };

            var arr8a = new int[] { 20, 4, 8 };
            var arr8b = new int[] { 20, 4, 26, 3, 9, 8 };
            var arr8c = new int[] { 20, 4, 26, 3, 21, 9, 30, 2, 7, 11, 8 };

            var tree = new AvlTree <int>();

            foreach (var i in arr15c)
            {
                tree.Add(i);
                tree.Print();
            }

            Console.ReadKey();
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            AvlTree tree = new AvlTree();

            string line;

            string[] words;
            string   command;

            Console.Write(">>");

            while ((line = Console.ReadLine()) != null && line != "")
            {
                words = line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);

                if (words.Length > 0)
                {
                    command = words[0];

                    switch (command)
                    {
                    case "+":
                        for (int i = 2; i < words.Length; i += 2)
                        {
                            int value;
                            if (int.TryParse(words[i], out value))
                            {
                                tree.Add(words[i - 1], value);
                            }
                        }
                        Console.WriteLine();
                        break;

                    case "-":
                        for (int i = 1; i < words.Length; i++)
                        {
                            tree.Remove(words[i]);
                        }
                        break;

                    case "save":
                        if (words.Length > 1)
                        {
                            tree.SaveToFile(words[1]);
                        }
                        break;

                    case "load":
                        if (words.Length > 1)
                        {
                            tree.LoadFromFile(words[1]);
                        }
                        break;

                    case "search":
                        if (words.Length > 1)
                        {
                            int value;
                            Console.WriteLine(tree.Search(words[1], out value) ? $"\nValue found: {value}" : "\nNot found\n");
                        }
                        break;

                    case "output":
                        tree.Output();
                        break;

                    case "clear":
                        tree.Clear();
                        break;

                    default:
                        Console.WriteLine("\nThere is no such command.\n");
                        break;
                    }
                }

                Console.Write("\n>>");
            }
        }