static void SearchExample()
        {
            var tree = new AATree<int>();
            tree.Add(4);
            tree.Add(10);
            tree.Add(2);
            tree.Add(6);
            tree.Add(12);
            tree.Add(3);
            tree.Add(1);
            tree.Add(8);
            tree.Add(13);
            tree.Add(11);
            tree.Add(5);
            tree.Add(9);
            tree.Add(7);

            Console.WriteLine("All results should be true");
            Console.WriteLine(tree.Find(4));
            Console.WriteLine(!tree.Find(-5));
            Console.WriteLine(!tree.Find(100));
            Console.WriteLine(!tree.Find(15));
            Console.WriteLine(tree.Find(13));
            Console.WriteLine(tree.Find(7));
        }
Example #2
0
    static void SearchExample()
    {
        var tree = new AATree<int>();
        tree.Add(4);
        tree.Add(10);
        tree.Add(2);
        tree.Add(6);
        tree.Add(12);
        tree.Add(3);
        tree.Add(1);
        tree.Add(8);
        tree.Add(13);
        tree.Add(11);
        tree.Add(5);
        tree.Add(9);
        tree.Add(7);

        Console.WriteLine("All results should be true");
        Console.WriteLine(tree.Find(4));
        Console.WriteLine(!tree.Find(-5));
        Console.WriteLine(!tree.Find(100));
        Console.WriteLine(!tree.Find(15));
        Console.WriteLine(tree.Find(13));
        Console.WriteLine(tree.Find(7));
    }
    // Test program; should print min and max and nothing else
    public static void Main(string[] args)
    {
        AATree <int> t    = new AATree <int>(-9999);
        const int    NUMS = 40000;
        const int    GAP  = 307;

        Console.WriteLine("Checking... (no bad output means success)");

        t.Insert(NUMS * 2);
        t.Insert(NUMS * 3);
        for (int i = GAP; i != 0; i = (i + GAP) % NUMS)
        {
            t.Insert(i);
        }
        Console.WriteLine("Inserts complete");

        t.Remove(t.FindMax( ));
        for (int i = 1; i < NUMS; i += 2)
        {
            t.Remove(i);
        }
        t.Remove(t.FindMax( ));
        Console.WriteLine("Removes complete");


        if (t.FindMin( ) != 2 || t.FindMax( ) != NUMS - 2)
        {
            Console.WriteLine("FindMin or FindMax error!");
        }

        for (int i = 2; i < NUMS; i += 2)
        {
            if (t.Find(i) != i)
            {
                Console.WriteLine("Error: find fails for " + i);
            }
        }

        for (int i = 1; i < NUMS; i += 2)
        {
            if (t.Contains(i))
            {
                Console.WriteLine("Error: Found deleted item " + i);
            }
        }
    }