Esempio n. 1
0
        public void Clear()
        {
            QueueUsingArray <int> queue = new QueueUsingArray <int>();

            queue.Enqueue(10);
            queue.Enqueue(20);
            queue.Enqueue(30);
            queue.Enqueue(40);

            //10 <- 20 <- 30 <- 40

            queue.Dequeue();
            queue.Dequeue();
            queue.Dequeue();
            queue.Dequeue();


            Assert.AreEqual(queue.Count, 0);
        }
Esempio n. 2
0
        public void Peek()
        {
            QueueUsingArray <int> queue = new QueueUsingArray <int>();

            queue.Enqueue(10);
            queue.Enqueue(20);
            queue.Enqueue(30);
            queue.Enqueue(40);

            //10 <- 20 <- 30 <- 40

            queue.Dequeue();
            queue.Dequeue();

            //30 <- 40


            Assert.AreEqual(queue.Peek(), 30);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            #region LinkedList
            SingleLinkedList <int>     singleLL = new SingleLinkedList <int>();
            SingleLinkedListNode <int> snode1   = new SingleLinkedListNode <int>(20);
            singleLL.AddFirst(snode1); singleLL.Add(30); singleLL.AddLast(90); singleLL.AddFirst(11);
            singleLL.PrintList("");

            DoubleLinkedList <int>     doubleLL = new DoubleLinkedList <int>();
            DoubleLinkedListNode <int> node1    = new DoubleLinkedListNode <int>(45);
            doubleLL.AddFirst(node1); doubleLL.AddLast(90); doubleLL.Add(33); doubleLL.Add(30); doubleLL.Add(31);
            doubleLL.PrintList("");

            #endregion

            #region Stack
            // To Evaluate PostFix Expression.
            PostFixCalculator();
            #endregion

            #region Queue
            QueueUsingArray <int> queue1 = new QueueUsingArray <int>();
            queue1.Enqueue(50); queue1.Enqueue(60); queue1.Enqueue(70); queue1.Enqueue(80); queue1.Enqueue(90);
            queue1.Dequeue(); queue1.Dequeue();
            queue1.Enqueue(50); queue1.Enqueue(60); queue1.Enqueue(70); queue1.Enqueue(80); queue1.Enqueue(90);
            queue1.Dequeue(); queue1.Dequeue();
            queue1.PrintQueue();

            QueueUsingList <int> queue2 = new QueueUsingList <int>();
            queue2.Enqueue(50); queue2.Enqueue(60); queue2.Enqueue(70); queue2.Enqueue(80); queue2.Enqueue(90);
            queue2.Dequeue(); queue2.Dequeue();
            queue2.Enqueue(50); queue2.Enqueue(60); queue2.Enqueue(70); queue2.Enqueue(80); queue2.Enqueue(90);
            queue2.Dequeue(); queue2.Dequeue();
            queue2.PrintQueue();
            #endregion

            #region Trees



            #endregion
        }
        public void VerifyPopInQueue()
        {
            var actual = new QueueUsingArray(3);

            actual.Enqueue(12);
            actual.Enqueue(14);
            actual.Enqueue(16);

            Assert.AreEqual(3, actual.Count());

            var value = actual.Dequeue();

            Assert.AreEqual(12, value);
            Assert.AreEqual(2, actual.Count());

            value = actual.Dequeue();
            Assert.AreEqual(14, value);
            Assert.AreEqual(1, actual.Count());

            value = actual.Dequeue();
            Assert.AreEqual(16, value);
            Assert.AreEqual(0, actual.Count());
        }