Ejemplo n.º 1
0
        public void AcceptVisitorExample()
        {
            var priorityQueue = new PriorityQueue<string, int>(PriorityQueueType.Minimum);
            priorityQueue.Enqueue("cat");
            priorityQueue.Enqueue("dog");
            priorityQueue.Enqueue("canary");

            // There should be 3 items in the priorityQueue.
            Assert.AreEqual(3, priorityQueue.Count);

            // Create a visitor that will simply count the items in the priorityQueue.
            var visitor =
                new CountingVisitor<string>();

            // Make priorityQueue call IVisitor<T>.Visit on all items contained.
            priorityQueue.AcceptVisitor(visitor);

            // The counting visitor would have visited 3 items.
            Assert.AreEqual(3, visitor.Count);
        }
Ejemplo n.º 2
0
        public void AcceptVisitorExample()
        {
            var priorityQueue = new PriorityQueue <string, int>(PriorityQueueType.Minimum);

            priorityQueue.Enqueue("cat");
            priorityQueue.Enqueue("dog");
            priorityQueue.Enqueue("canary");

            // There should be 3 items in the priorityQueue.
            Assert.AreEqual(3, priorityQueue.Count);

            // Create a visitor that will simply count the items in the priorityQueue.
            var visitor =
                new CountingVisitor <string>();

            // Make priorityQueue call IVisitor<T>.Visit on all items contained.
            priorityQueue.AcceptVisitor(visitor);

            // The counting visitor would have visited 3 items.
            Assert.AreEqual(3, visitor.Count);
        }