예제 #1
0
        public void DequeueOnEmptyQueueThrowsQueueEmptyExceptionTest()
        {
            LinkedListQueue target = new LinkedListQueue(); // TODO: Initialize to an appropriate value

            target.Dequeue();
            Assert.Fail("Dequeued from empty queue didn't throw QueueEmptyException");
        }
        public void TestLinkedListQueuePeek()
        {
            LinkedListQueue<int> queue = new LinkedListQueue<int>();

            // enqueue some items to test
            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);
            queue.Enqueue(4);
            queue.Enqueue(5);

            // check that after peek we have the correct value but the item
            // is not deleted
            Assert.AreEqual(1, queue.Peek());
            Assert.AreEqual(5, queue.Count);
            queue.Dequeue();
            Assert.AreEqual(2, queue.Peek());
            Assert.AreEqual(4, queue.Count);
            queue.Dequeue();
            Assert.AreEqual(3, queue.Peek());
            Assert.AreEqual(3, queue.Count);
            queue.Dequeue();
            Assert.AreEqual(4, queue.Peek());
            Assert.AreEqual(2, queue.Count);
            queue.Dequeue();
            Assert.AreEqual(5, queue.Peek());
            Assert.AreEqual(1, queue.Count);
            queue.Dequeue();
        }
예제 #3
0
        public IQueue <Key> keys()
        {
            IQueue <Key> q = new LinkedListQueue <Key>();

            inorder(root, q);
            return(q);
        }
예제 #4
0
파일: Program.cs 프로젝트: viaches/leetcode
        static void Main(string[] args)
        {
            var arrayQueue = new ArrayQueue <string>();

            arrayQueue.Enqueue("1");
            arrayQueue.Enqueue("2");
            arrayQueue.Enqueue("3");
            arrayQueue.Enqueue("4");
            arrayQueue.Enqueue("5");

            arrayQueue.Dequeue();
            arrayQueue.Dequeue();
            arrayQueue.Dequeue();
            arrayQueue.Dequeue();

            var linkedListQueue = new LinkedListQueue <string>();

            linkedListQueue.Enqueue("1");
            linkedListQueue.Enqueue("2");
            linkedListQueue.Enqueue("3");
            linkedListQueue.Enqueue("4");
            linkedListQueue.Enqueue("5");

            linkedListQueue.Dequeue();
            linkedListQueue.Dequeue();
            linkedListQueue.Dequeue();
            linkedListQueue.Dequeue();
        }
예제 #5
0
        private static void QueueTests()
        {
            var arrayValueTypeQueue = new ArrayQueue <int>();

            Console.WriteLine("ArrayQueue<int> test:");
            TestValueTypeQueue(arrayValueTypeQueue);

            Console.WriteLine("=======================================");
            Console.WriteLine();

            var linkedListValueTypeQueue = new LinkedListQueue <int>();

            Console.WriteLine("LinkedListQueue<int> test:");
            TestValueTypeQueue(linkedListValueTypeQueue);

            Console.WriteLine("=======================================");
            Console.WriteLine();

            var arrayReferenceTypeQueue = new ArrayQueue <string>();

            Console.WriteLine("ArrayQueue<string> test:");
            TestReferenceTypeQueue(arrayReferenceTypeQueue);

            Console.WriteLine("=======================================");
            Console.WriteLine();

            var linkedListReferenceTypeQueue = new LinkedListQueue <string>();

            Console.WriteLine("LinkedListQueue<string> test:");
            TestReferenceTypeQueue(linkedListReferenceTypeQueue);

            Console.WriteLine("=======================================");
            Console.WriteLine();
        }
        public void TestLinkedListQueuePeek()
        {
            LinkedListQueue <int> queue = new LinkedListQueue <int>();

            // enqueue some items to test
            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);
            queue.Enqueue(4);
            queue.Enqueue(5);

            // check that after peek we have the correct value but the item
            // is not deleted
            Assert.AreEqual(1, queue.Peek());
            Assert.AreEqual(5, queue.Count);
            queue.Dequeue();
            Assert.AreEqual(2, queue.Peek());
            Assert.AreEqual(4, queue.Count);
            queue.Dequeue();
            Assert.AreEqual(3, queue.Peek());
            Assert.AreEqual(3, queue.Count);
            queue.Dequeue();
            Assert.AreEqual(4, queue.Peek());
            Assert.AreEqual(2, queue.Count);
            queue.Dequeue();
            Assert.AreEqual(5, queue.Peek());
            Assert.AreEqual(1, queue.Count);
            queue.Dequeue();
        }
예제 #7
0
 public LinkedListQueueOneElement()
 {
     queue = new LinkedListQueue <int>()
     {
         oneValue
     };
 }
예제 #8
0
 private void GeneratePopulatedExample()
 {
     PopulatedLinkedListQueue = new LinkedListQueue <string>();
     foreach (var item in Items)
     {
         PopulatedLinkedListQueue.Enqueue(item);
     }
 }
        public void Enqueue_Adds_To_Count()
        {
            IQueue <int> queue = new LinkedListQueue <int>();

            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);
            Assert.Equal(3, queue.Count);
        }
        public void Enqueue_And_Dequeue_Single_Item()
        {
            IQueue <int> queue = new LinkedListQueue <int>();

            queue.Enqueue(1);
            queue.Enqueue(2);
            var item = queue.Peek();

            Assert.Equal(1, item);
        }
예제 #11
0
        public void CountTest()
        {
            LinkedListQueue target = new LinkedListQueue();

            for (int i = 0; i < 1000000; i++)
            {
                Assert.AreEqual <int>(target.Count, i, string.Format("After adding {0} entries to LinkedListQueue, Count returns {1}", i, target.Count));
                target.Enqueue(i);
            }
        }
예제 #12
0
        public void LinkedListQueueEnqueueTest()
        {
            var queue = new LinkedListQueue <int>();

            for (var i = 0; i < Elements; i++)
            {
                queue.Enqueue(i * 10);
            }
            Assert.AreEqual(0, queue.Peek());
        }
예제 #13
0
        public void QueueIsEnptyWhenAllElementsAreRemoved()
        {
            var sut = new LinkedListQueue <int>();

            sut.Enqueue(1);
            sut.Enqueue(2);
            Assert.Equal(1, sut.Dequeue());
            Assert.Equal(2, sut.Dequeue());
            Assert.True(sut.IsEmpty);
        }
예제 #14
0
        public void NonEmptyQueueReadsNotEmptyTest()
        {
            LinkedListQueue target = new LinkedListQueue();

            target.Enqueue(0);
            for (int i = 0; i < 1000000; i++)
            {
                target.Enqueue(i);
                Assert.IsFalse(target.IsEmpty, string.Format("LinkedListQueue reads as empty after adding {0} objects and never removing any", i + 1));
            }
        }
        public void Dequeue_Subtracts_To_Count()
        {
            IQueue <int> queue = new LinkedListQueue <int>();

            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);
            queue.Dequeue();
            queue.Dequeue();
            Assert.Equal(1, queue.Count);
        }
        public void TestLinkedListQueueToString()
        {
            LinkedListQueue <int> queue = new LinkedListQueue <int>();

            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);
            queue.Enqueue(4);
            queue.Enqueue(5);

            Assert.AreEqual("1, 2, 3, 4, 5", queue.ToString());
        }
예제 #17
0
        public override void Init()
        {
            _linkedListQueue = new LinkedListQueue <int>();
            _arrayQueue      = new ArrayQueue <int>(Elements);

            for (var i = 0; i < Elements; i++)
            {
                _linkedListQueue.Enqueue(i * 10);
                _arrayQueue.Enqueue(i * 10);
            }
            base.Init();
        }
예제 #18
0
        public void CircularQueueRemovesOldElementsToEnqueueNewOnes1()
        {
            var sut = new LinkedListQueue <int>();

            sut.Enqueue(1);
            sut.Enqueue(2);
            Assert.Equal(1, sut.Dequeue());
            Assert.Equal(2, sut.Dequeue());
            sut.Enqueue(4);
            Assert.Equal(4, sut.Dequeue());
            Assert.True(sut.IsEmpty);
        }
        public void TestLinkedListQueueContains()
        {
            LinkedListQueue <int> queue = new LinkedListQueue <int>();

            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);
            queue.Enqueue(4);
            queue.Enqueue(5);

            Assert.IsTrue(queue.Contains(5));
        }
예제 #20
0
        public void LinkedListTest_當存入輸入時_IsEmpty為false()
        {
            var expect = new int[] { 24, 12, 16, 22 };

            var queue = new LinkedListQueue <int>();

            foreach (var i in expect)
            {
                queue.Enqueue(i);
            }

            Assert.IsFalse(queue.IsEmpty);
        }
예제 #21
0
        public void QueueStackWorksInFifoOrder()
        {
            var sut = new LinkedListQueue <int>();

            for (var i = 0; i < 100; i++)
            {
                sut.Enqueue(i);
            }
            for (var i = 0; i < 100; i++)
            {
                Assert.Equal(i, sut.Dequeue());
            }
        }
        public void TestLinkedListQueueClear()
        {
            LinkedListQueue <int> queue = new LinkedListQueue <int>();

            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);
            queue.Enqueue(4);
            queue.Enqueue(5);

            queue.Clear();

            Assert.AreEqual(0, queue.Count);
        }
예제 #23
0
        public void QueueWorksInFifoOrderWhenIntermittentEnqueuesAccure()
        {
            var sut = new LinkedListQueue <int>();

            sut.Enqueue(1);
            sut.Enqueue(2);
            sut.Enqueue(3);
            Assert.Equal(1, sut.Dequeue());
            sut.Enqueue(4);
            sut.Enqueue(5);
            Assert.Equal(2, sut.Dequeue());
            Assert.Equal(3, sut.Dequeue());
            Assert.Equal(4, sut.Dequeue());
            Assert.Equal(5, sut.Dequeue());
        }
        public void QueueTest()
        {
            var q = new LinkedListQueue <int>();

            q.Enqueue(1);
            q.Enqueue(2);
            Assert.IsTrue(q.Count == 2);
            int i = q.Dequeue();

            Assert.IsTrue(i == 1);
            Assert.IsTrue(q.Count == 1);
            i = q.Dequeue();
            Assert.IsTrue(i == 2);
            Assert.IsTrue(q.Count == 0);
        }
        public void TestLinkedListQueueEnqueue()
        {
            LinkedListQueue<int> queue = new LinkedListQueue<int>();

            // enqueue some items to test and check that the items are inserted correctly
            queue.Enqueue(1);
            Assert.AreEqual(1, queue.Count);
            queue.Enqueue(2);
            Assert.AreEqual(2, queue.Count);
            queue.Enqueue(3);
            Assert.AreEqual(3, queue.Count);
            queue.Enqueue(4);
            Assert.AreEqual(4, queue.Count);
            queue.Enqueue(5);
            Assert.AreEqual(5, queue.Count);
        }
예제 #26
0
        public void TestLinkedListQueue()
        {
            var queue = new LinkedListQueue <int>();

            for (var i = 0; i < 10; i++)
            {
                queue.Enqueue(i);
                Console.WriteLine(queue);

                if (i % 3 == 2)
                {
                    queue.Dequeue();
                    Console.WriteLine(queue);
                }
            }
        }
        public void TestLinkedListQueueEnqueue()
        {
            LinkedListQueue <int> queue = new LinkedListQueue <int>();

            // enqueue some items to test and check that the items are inserted correctly
            queue.Enqueue(1);
            Assert.AreEqual(1, queue.Count);
            queue.Enqueue(2);
            Assert.AreEqual(2, queue.Count);
            queue.Enqueue(3);
            Assert.AreEqual(3, queue.Count);
            queue.Enqueue(4);
            Assert.AreEqual(4, queue.Count);
            queue.Enqueue(5);
            Assert.AreEqual(5, queue.Count);
        }
예제 #28
0
        public static void TestLinkedListQueue()
        {
            LinkedListQueue <int> linkedListQueue = new LinkedListQueue <int>();

            linkedListQueue.Enqueue(3);
            linkedListQueue.Enqueue(4);
            linkedListQueue.Enqueue(5);
            linkedListQueue.Enqueue(6);
            linkedListQueue.Enqueue(7);
            linkedListQueue.Enqueue(8);
            linkedListQueue.PrintItems();
            linkedListQueue.Dequeue();
            linkedListQueue.Dequeue();
            linkedListQueue.PrintItems();
            Console.ReadLine();
        }
예제 #29
0
        public void LinkedListQueue()
        {
            var queue = new LinkedListQueue <int>();

            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);
            queue.Enqueue(4);
            queue.Enqueue(5);

            Assert.AreEqual(1, queue.Dequeue());
            Assert.AreEqual(2, queue.Dequeue());
            Assert.AreEqual(3, queue.Dequeue());
            Assert.AreEqual(4, queue.Dequeue());
            Assert.AreEqual(5, queue.Dequeue());
            Assert.AreEqual(true, queue.IsEmpty());
        }
예제 #30
0
        public void Can_enqueue_data()
        {
            var linkedListQueue = new LinkedListQueue <int>();

            linkedListQueue.Enqueue(1);
            linkedListQueue.Enqueue(2);
            linkedListQueue.Enqueue(3);
            linkedListQueue.Enqueue(4);

            Assert.Equal(4, linkedListQueue.Length);
            var head = linkedListQueue.Head;

            Assert.Equal(1, head.Data);
            Assert.Equal(2, head.Next.Data);
            Assert.Equal(3, head.Next.Next.Data);
            Assert.Equal(4, head.Next.Next.Next.Data);
        }
        public void Enqueue_And_Dequeue_Multiple_Items()
        {
            IQueue <int> queue = new LinkedListQueue <int>();

            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);
            queue.Enqueue(4);
            queue.Enqueue(5);
            queue.Dequeue();
            queue.Dequeue();
            queue.Dequeue();
            queue.Dequeue();
            var item = queue.Peek();

            Assert.Equal(5, item);
        }
        public void TestLinkedListQueueDequeue_ThrowsException()
        {
            LinkedListQueue<int> queue = new LinkedListQueue<int>();

            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);
            queue.Enqueue(4);
            queue.Enqueue(5);

            queue.Dequeue();
            queue.Dequeue();
            queue.Dequeue();
            queue.Dequeue();
            queue.Dequeue();
            queue.Dequeue();
        }
        public void TestLinkedListQueueDequeue_ThrowsException()
        {
            LinkedListQueue <int> queue = new LinkedListQueue <int>();

            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);
            queue.Enqueue(4);
            queue.Enqueue(5);

            queue.Dequeue();
            queue.Dequeue();
            queue.Dequeue();
            queue.Dequeue();
            queue.Dequeue();
            queue.Dequeue();
        }
예제 #34
0
        static void Main(string[] args)
        {
            LinkedListQueue<int> queue = new LinkedListQueue<int>();

            for (int i = 1; i <= 5; i++)
            {
                queue.Enqueue(i);
            }

            Console.WriteLine("Count: {0}", queue.Count);

            Console.WriteLine("The peek is {0}", queue.Peek());

            for (int i = 1; i <=  4; i++)
            {
                queue.Dequeue();
            }

            Console.WriteLine("After dequeue 4 item the peek is {0}", queue.Peek());
        }
        public void TestLinkedListQueueDequeue()
        {
            LinkedListQueue<int> queue = new LinkedListQueue<int>();

            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);
            queue.Enqueue(4);
            queue.Enqueue(5);

            Assert.AreEqual(1, queue.Dequeue());
            Assert.AreEqual(4, queue.Count);
            Assert.AreEqual(2, queue.Dequeue());
            Assert.AreEqual(3, queue.Count);
            Assert.AreEqual(3, queue.Dequeue());
            Assert.AreEqual(2, queue.Count);
            Assert.AreEqual(4, queue.Dequeue());
            Assert.AreEqual(1, queue.Count);
            Assert.AreEqual(5, queue.Dequeue());
            Assert.AreEqual(0, queue.Count);
        }
        public void SortByDroid()
        {
            LinkedListStack<AstromechDroid> astromechList = new LinkedListStack<AstromechDroid>();
            LinkedListStack<JanitorDroid> janitorList = new LinkedListStack<JanitorDroid>();
            LinkedListStack<ProtocolDroid> protocolList = new LinkedListStack<ProtocolDroid>();
            LinkedListStack<UtilityDroid> utilityList = new LinkedListStack<UtilityDroid>();

            LinkedListQueue<IDroid> tempList = new LinkedListQueue<IDroid>();

            foreach(Droid d in droidCollection)
            {
                if(d is AstromechDroid)
                {
                    astromechList.Add((AstromechDroid)d);
                }
                else if(d is JanitorDroid)
                {
                    janitorList.Add((JanitorDroid)d);
                }
                else if(d is ProtocolDroid)
                {
                    protocolList.Add((ProtocolDroid)d);
                }
                else if(d is UtilityDroid)
                {
                    utilityList.Add((UtilityDroid)d);
                }
            }

            while(astromechList.lastNode.Tail != null)
            {
                tempList.Enqueue(astromechList.PopOff());
            }
            tempList.Enqueue(astromechList.PopOff());

            while(janitorList.lastNode.Tail != null)
            {
                tempList.Enqueue(janitorList.PopOff());
            }
            tempList.Enqueue(janitorList.PopOff());

            while(protocolList.lastNode.Tail != null)
            {
                tempList.Enqueue(protocolList.PopOff());
            }
            tempList.Enqueue(protocolList.PopOff());

            while(utilityList.lastNode.Tail != null)
            {
                tempList.Enqueue(utilityList.PopOff());
            }
            tempList.Enqueue(utilityList.PopOff());

            droidCollection = new IDroid[lengthOfCollection];
            int counter = 0;
            while(counter < lengthOfCollection)
            {
                if(tempList.lastNode != null)
                {
                    droidCollection[counter] = tempList.Dequeue();
                    counter++;
                }
            }
        }
예제 #37
0
 public MapperChain()
 {
     this.mappers = new LinkedListQueue<EventMapper>();
 }
        public void TestLinkedListQueuePeek_ThrowsException()
        {
            LinkedListQueue<int> queue = new LinkedListQueue<int>();

            // enqueue some items to test
            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);
            queue.Enqueue(4);
            queue.Enqueue(5);

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

            queue.Peek();
        }
        public void TestLinkedListQueueClear()
        {
            LinkedListQueue<int> queue = new LinkedListQueue<int>();

            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);
            queue.Enqueue(4);
            queue.Enqueue(5);

            queue.Clear();

            Assert.AreEqual(0, queue.Count);
        }
        public void TestLinkedListQueueToString()
        {
            LinkedListQueue<int> queue = new LinkedListQueue<int>();

            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);
            queue.Enqueue(4);
            queue.Enqueue(5);

            Assert.AreEqual("1, 2, 3, 4, 5", queue.ToString());
        }
예제 #41
0
        public void E1329()
        {
            LinkedListQueue<string> queue = new LinkedListQueue<string>();
            Assert.AreEqual(0, queue.Size);
            queue.Enqueue(new Node<string>(1));
            Assert.AreEqual(1, queue.Size);
            queue.Enqueue(new Node<string>(2));
            Assert.AreEqual(2, queue.Size);
            queue.Enqueue(new Node<string>(3));
            Assert.AreEqual(3, queue.Size);

            queue.Dequeue();
            Assert.AreEqual(2, queue.Size);
            queue.Dequeue();
            Assert.AreEqual(1, queue.Size);
            queue.Dequeue();
            Assert.AreEqual(0, queue.Size);
            Assert.IsTrue(queue.IsEmpty());

            try
            {
                queue.Dequeue();
                throw new ApplicationException("Test failed");
            }
            catch (Exception)
            { }
        }
        public void TestLinkedListQueueContains()
        {
            LinkedListQueue<int> queue = new LinkedListQueue<int>();

            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);
            queue.Enqueue(4);
            queue.Enqueue(5);

            Assert.IsTrue(queue.Contains(5));
        }