示例#1
0
        public void ShouldVisitEachNodeInDescendingOrder()
        {
            AndersonTree <int, int> tree = new AndersonTree <int, int>();

            Stack <int> data = new Stack <int>(10);

            for (int i = 0; i < 10; i++)
            {
                data.Push(i * 10);
                tree.Add(i * 10, i * 10);
            }

            var visitor =
                new InOrderVisitor <int, int>(
                    new Visitor <int, int>(
                        (key, value, state) => Assert.AreEqual(data.Pop(), value)));

            tree.Accept(visitor, true);
        }
示例#2
0
        public void ShouldVisitEachNodeInAscendingOrder()
        {
            AndersonTree <int, int> tree = new AndersonTree <int, int>();

            Queue <int> data = new Queue <int>(10);

            for (int i = 0; i < 10; i++)
            {
                data.Enqueue(i * 10);
                tree.Add(i * 10, i * 10);
            }

            var visitor =
                new InOrderVisitor <int, int>(
                    new Visitor <int, int>(
                        (key, value, state) => Assert.AreEqual(data.Dequeue(), value)));

            tree.Accept(visitor, false);
        }