Esempio n. 1
0
        private static void Main()
        {
            EasyQueue <int> easyQueue = new EasyQueue <int>();

            easyQueue.Enqueue(1);
            easyQueue.Enqueue(2);
            easyQueue.Enqueue(3);
            Console.WriteLine(easyQueue.Contains(5));

            Console.WriteLine(easyQueue.Dequeue());
            Console.WriteLine(easyQueue.Peek());
            Console.WriteLine(easyQueue.Dequeue());

            ArrayQueue <int> arrayQueue = new ArrayQueue <int>();

            arrayQueue.Enqueue(10);
            arrayQueue.Enqueue(20);
            arrayQueue.Enqueue(30);
            Console.WriteLine(arrayQueue.Contains(10));

            Console.WriteLine(arrayQueue.Dequeue());
            Console.WriteLine(arrayQueue.Dequeue());
            Console.WriteLine(arrayQueue.Dequeue());

            LinkedQueue <int> linkedQueue = new LinkedQueue <int>();

            linkedQueue.Enqueue(100);
            linkedQueue.Enqueue(200);
            linkedQueue.Enqueue(300);

            Console.WriteLine(linkedQueue.Dequeue());
            Console.WriteLine(linkedQueue.PeekFirst());
            Console.WriteLine(linkedQueue.PeekLast());
            Console.WriteLine(linkedQueue.Dequeue());
        }
Esempio n. 2
0
        public void EasyQueueTest()
        {
            var queue = new EasyQueue <int>();

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

            Assert.AreEqual(3, queue.Count);

            var result = queue.Dequeue();

            Assert.AreEqual(1, result);
            Assert.AreEqual(2, queue.Count);

            result = queue.Peek();
            Assert.AreEqual(2, result);

            queue.Dequeue();
            queue.Dequeue();
            Assert.ThrowsException <InvalidOperationException>(() => queue.Dequeue());
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            var easyqueue = new EasyQueue <int>();

            easyqueue.Enqueue(1);
            easyqueue.Enqueue(2);
            easyqueue.Enqueue(3);
            easyqueue.Enqueue(4);
            easyqueue.Enqueue(5);
            Console.WriteLine(easyqueue.Dequeue());
            Console.WriteLine(easyqueue.Peek());
            Console.WriteLine(easyqueue.Dequeue());
            Console.WriteLine();

            var array = new ArrayQueue <int>(10);

            array.Enqueue(100);
            array.Enqueue(101);
            array.Enqueue(102);
            array.Enqueue(103);
            array.Enqueue(104);
            Console.WriteLine(array.Dequeue());
            Console.WriteLine(array.Peek());
            Console.WriteLine(array.Dequeue());
            Console.WriteLine(array.Dequeue());
            Console.WriteLine(array.Dequeue());
            Console.WriteLine(array.Peek());
            Console.WriteLine();

            var linkedQueue = new LinkedQueue <int>();

            linkedQueue.Enqueue(200);
            linkedQueue.Enqueue(201);
            linkedQueue.Enqueue(202);
            linkedQueue.Enqueue(203);
            linkedQueue.Enqueue(204);
            Console.WriteLine(linkedQueue.Count);
            Console.WriteLine(linkedQueue.Dequeue());
            Console.WriteLine(linkedQueue.Dequeue());
            Console.WriteLine(linkedQueue.Dequeue());
            Console.WriteLine(linkedQueue.Peek());
            Console.WriteLine(linkedQueue.Dequeue());
            Console.WriteLine(linkedQueue.Peek());
            Console.WriteLine(linkedQueue.Count);
            Console.WriteLine();
            var easydeque = new EasyDeque <int>();

            easydeque.PushFront(11);
            easydeque.Pushback(222);
            easydeque.PushFront(13);
            easydeque.Pushback(224);
            easydeque.PushFront(15);
            easydeque.Pushback(226);
            easydeque.PushFront(17);
            easydeque.Pushback(228);
            Console.WriteLine(easydeque.Popback());
            Console.WriteLine(easydeque.PeekBack());
            Console.WriteLine(easydeque.Popback());
            Console.WriteLine(easydeque.PeekBack());
            Console.WriteLine(easydeque.Popback());
            Console.WriteLine(easydeque.Popfront());
            Console.WriteLine(easydeque.PeekFront());
            Console.WriteLine(easydeque.Popfront());
            Console.WriteLine(easydeque.Popfront());
            Console.WriteLine(easydeque.PeekFront());
            Console.WriteLine();

            var duplexdeque = new DuplexLinkedDeque <int>();

            duplexdeque.PushBack(1000);
            duplexdeque.PushBack(1001);
            duplexdeque.PushBack(1002);
            duplexdeque.PushBack(1003);
            duplexdeque.PushFront(2000);
            duplexdeque.PushFront(2001);
            duplexdeque.PushFront(2002);
            Console.WriteLine(duplexdeque.PopBack());
            Console.WriteLine(duplexdeque.PopBack());
            Console.WriteLine(duplexdeque.PeekBack());
            Console.WriteLine(duplexdeque.PopBack());
            Console.WriteLine(duplexdeque.PopFront());
            Console.WriteLine(duplexdeque.PopFront());
            Console.WriteLine(duplexdeque.PopFront());
            Console.ReadLine();
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            var linkedDeque = new EasyDeque <int>();

            linkedDeque.PushFront(1);
            linkedDeque.PushFront(2);
            linkedDeque.PushFront(3);
            linkedDeque.PushBack(4);
            linkedDeque.PushBack(5);

            Console.WriteLine(linkedDeque.PopFront());
            Console.WriteLine(linkedDeque.PopFront());
            Console.WriteLine(linkedDeque.PopBack());
            Console.WriteLine(linkedDeque.PopBack());
            Console.WriteLine(linkedDeque.PopFront());


            Console.ReadLine();

            var easyDeque = new EasyDeque <int>();

            easyDeque.PushFront(1);
            easyDeque.PushFront(2);
            easyDeque.PushFront(3);
            easyDeque.PushBack(4);
            easyDeque.PushBack(5);
            easyDeque.PushFront(6);
            easyDeque.PushBack(7);

            Console.WriteLine(easyDeque.PopFront());
            Console.WriteLine(easyDeque.PopFront());
            Console.WriteLine(easyDeque.PopFront());
            Console.WriteLine(easyDeque.PopFront());
            Console.WriteLine(easyDeque.PopFront());


            Console.ReadLine();


            var linkedQueue = new LinkedQueue <int>();

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

            Console.WriteLine(linkedQueue.Dequeue());
            Console.WriteLine(linkedQueue.Peek());
            Console.WriteLine(linkedQueue.Dequeue());
            Console.WriteLine(linkedQueue.Dequeue());
            Console.WriteLine(linkedQueue.Dequeue());

            Console.ReadLine();

            var arrayQueue = new ArrayQueue <int>(5);

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

            Console.WriteLine(arrayQueue.Dequeue());
            Console.WriteLine(arrayQueue.Peek());
            Console.WriteLine(arrayQueue.Dequeue());
            Console.WriteLine(arrayQueue.Dequeue());
            Console.WriteLine(arrayQueue.Dequeue());

            Console.ReadLine();

            var easyQueue = new EasyQueue <int>();

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

            Console.WriteLine(easyQueue.Dequeue());
            Console.WriteLine(easyQueue.Peek());
            Console.WriteLine(easyQueue.Dequeue());

            Console.ReadLine();
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            var duplexLinkedDeque = new DuplexLinkedDeque <int>();

            duplexLinkedDeque.PushFront(1);
            duplexLinkedDeque.PushFront(2);
            duplexLinkedDeque.PushFront(3);// некоректно
            duplexLinkedDeque.PushBack(4);
            duplexLinkedDeque.PushBack(5);

            Console.WriteLine(duplexLinkedDeque.PopFront());
            Console.WriteLine(duplexLinkedDeque.PopFront());
            Console.WriteLine(duplexLinkedDeque.PopBack());
            Console.WriteLine(duplexLinkedDeque.PopBack());
            Console.WriteLine(duplexLinkedDeque.PopFront());

            Console.ReadLine();

            var easyDeque = new EasyDeque <int>();

            easyDeque.PushFront(1);
            easyDeque.PushFront(2);
            easyDeque.PushFront(3);
            easyDeque.PushBack(40);
            easyDeque.PushBack(50);
            easyDeque.PushFront(600);
            easyDeque.PushBack(700);

            Console.WriteLine(easyDeque.PopFront());
            Console.WriteLine(easyDeque.PopBack());
            Console.WriteLine(easyDeque.PopFront());
            Console.WriteLine(easyDeque.PopBack());


            Console.ReadLine();

            var linkedQueue = new LinkedQueue <int>();

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

            Console.WriteLine(linkedQueue.Dequeue());
            Console.WriteLine(linkedQueue.Peek());
            Console.WriteLine(linkedQueue.Dequeue());
            Console.WriteLine(linkedQueue.Dequeue());
            Console.WriteLine(linkedQueue.Dequeue());

            Console.ReadLine();


            var arrayQueue = new ArrayQueue <int>(10);

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

            Console.WriteLine(arrayQueue.Dequeue());
            Console.WriteLine(arrayQueue.Peek());
            Console.WriteLine(arrayQueue.Dequeue());

            Console.ReadLine();

            var easyQueue = new EasyQueue <int>();

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

            Console.WriteLine(easyQueue.Dequeue());
            Console.WriteLine(easyQueue.Peek());
            Console.WriteLine(easyQueue.Dequeue());

            Console.ReadLine();
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            // EasyQueue

            Console.WriteLine("EasyQueue");
            var easyQueue = new EasyQueue <int>();

            easyQueue.Enqueue(1); // Добавление данных
            easyQueue.Enqueue(2);
            easyQueue.Enqueue(3);
            easyQueue.Enqueue(4);
            easyQueue.Enqueue(5);

            Console.WriteLine(easyQueue.Dequeue()); // Извлекаем первый елемент
            Console.WriteLine(easyQueue.Peek());    // Смотрим на Head
            Console.WriteLine(easyQueue.Dequeue()); // Извлекаем первый елемент снова
            Console.WriteLine();
            //--------------------------------------------------------------------

            // ArrayQueue

            Console.WriteLine("ArrayQueue");

            var arrayQueue = new ArrayQueue <int>(10);

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

            Console.WriteLine(arrayQueue.Dequeue());
            Console.WriteLine(arrayQueue.Peek());
            Console.WriteLine(arrayQueue.Dequeue());

            Console.WriteLine();
            //----------------------------------------------------------------------

            // LinkedQueue

            Console.WriteLine("LinkedQueue");

            var linkedQueue = new LinkedQueue <int>();

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

            Console.WriteLine(linkedQueue.Dequeue());
            Console.WriteLine(linkedQueue.Peek());
            Console.WriteLine(linkedQueue.Dequeue());
            Console.WriteLine(linkedQueue.Dequeue());
            Console.WriteLine(linkedQueue.Dequeue());

            Console.WriteLine();
            //----------------------------------------------------------------------

            Console.WriteLine("EasyDeque");

            var easyDeque = new EasyDeque <int>();

            easyDeque.PushFront(1);
            easyDeque.PushFront(2);
            easyDeque.PushFront(3);
            easyDeque.PushBack(40);
            easyDeque.PushBack(50);
            easyDeque.PushFront(600);
            easyDeque.PushBack(700);

            Console.WriteLine(easyDeque.PopFront());
            Console.WriteLine(easyDeque.PopFront());
            Console.WriteLine(easyDeque.PopFront());
            Console.WriteLine(easyDeque.PopBack());
            Console.WriteLine(easyDeque.PopFront());
            Console.WriteLine(easyDeque.PopBack());


            Console.WriteLine();
            //----------------------------------------------------------------------

            Console.WriteLine("DuplexLinkedDeque");

            var linkedDeque = new DuplexLinkedDeque <int>();

            linkedDeque.PushFront(1);
            linkedDeque.PushFront(2);
            linkedDeque.PushFront(3);
            linkedDeque.PushBack(4);
            linkedDeque.PushBack(5);

            Console.WriteLine(linkedDeque.PopFront());
            Console.WriteLine(linkedDeque.PopBack());


            Console.WriteLine();
            //----------------------------------------------------------------------



            Console.ReadLine();
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            Console.WriteLine("DuplexLinkedDeque");

            var duplexLinkedDeque = new DuplexLinkedDeque <int>();

            duplexLinkedDeque.PushFront(1);
            duplexLinkedDeque.PushFront(2);
            duplexLinkedDeque.PushFront(3);
            duplexLinkedDeque.PushBack(4);
            duplexLinkedDeque.PushBack(5);

            Console.WriteLine($"Count: {duplexLinkedDeque.Count}");

            Console.WriteLine($"PopFront: {duplexLinkedDeque.PopFront()}");
            Console.WriteLine($"PopFront: {duplexLinkedDeque.PopFront()}");
            Console.WriteLine($"PopBack: {duplexLinkedDeque.PopBack()}");
            Console.WriteLine($"PopBack: {duplexLinkedDeque.PopBack()}");
            //Console.WriteLine($"PopFront: {duplexLinkedDeque.PopFront()}");
            Console.WriteLine($"PopFront: {duplexLinkedDeque.PopBack()}");


            Console.WriteLine("\nEasyDeque");

            var easyDeque = new EasyDeque <int>();

            easyDeque.PushFront(1);
            easyDeque.PushFront(2);
            easyDeque.PushFront(3);
            easyDeque.PushBack(4);
            easyDeque.PushBack(5);
            easyDeque.PushFront(6);
            easyDeque.PushBack(7);
            //easyDeque.PuchFront(1);
            //easyDeque.PuchFront(2);
            //easyDeque.PuchFront(3);
            //easyDeque.PushBack(40);
            //easyDeque.PushBack(50);
            //easyDeque.PuchFront(600);
            //easyDeque.PushBack(700);

            Console.WriteLine($"Count: {easyDeque.Count}");

            Console.WriteLine($"PopFront: {easyDeque.PopFront()}");
            Console.WriteLine($"PopFront: {easyDeque.PopFront()}");
            Console.WriteLine($"PopFront: {easyDeque.PopFront()}");
            Console.WriteLine($"PopFront: {easyDeque.PopFront()}");
            Console.WriteLine($"PopFront: {easyDeque.PopFront()}");
            //Console.WriteLine($"PopBack: {easyDeque.PopBack()}");
            //Console.WriteLine($"PopFront: {easyDeque.PopFront()}");
            //Console.WriteLine($"PopBack: {easyDeque.PopBack()}");

            Console.WriteLine("\nLinkedQueue");

            var linkedQueue = new LinkedQueue <int>();

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

            Console.WriteLine($"Count: {linkedQueue.Count}");

            Console.WriteLine($"Dequeue: {linkedQueue.Dequeue()}");
            Console.WriteLine($"Peek: {linkedQueue.Peek()}");
            Console.WriteLine($"Dequeue: {linkedQueue.Dequeue()}");
            Console.WriteLine($"Dequeue: {linkedQueue.Dequeue()}");
            Console.WriteLine($"Dequeue: {linkedQueue.Dequeue()}");
            Console.WriteLine($"Dequeue: {linkedQueue.Dequeue()}");

            Console.WriteLine("\nArrayQueue");

            var arrayQueue = new ArrayQueue <int>(5);

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

            Console.WriteLine($"Count: {arrayQueue.Count}");

            Console.WriteLine($"Dequeue: {arrayQueue.Dequeue()}");
            Console.WriteLine($"Peek: {arrayQueue.Peek()}");
            Console.WriteLine($"Dequeue: {arrayQueue.Dequeue()}");
            Console.WriteLine($"Dequeue: {arrayQueue.Dequeue()}");
            Console.WriteLine($"Dequeue: {arrayQueue.Dequeue()}");
            Console.WriteLine($"Dequeue: {arrayQueue.Dequeue()}");

            Console.WriteLine("Когда очередь заканчивает, вытаскивает последний элемент:");
            Console.WriteLine($"Dequeue: {arrayQueue.Dequeue()}");

            Console.WriteLine("\nEasyQueue");

            var easyQueue = new EasyQueue <int>();

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

            Console.WriteLine($"Count: {easyQueue.Count}");

            Console.WriteLine($"Dequeue: {easyQueue.Dequeue()}");
            Console.WriteLine($"Peek: {easyQueue.Peek()}");
            Console.WriteLine($"Dequeue: {easyQueue.Dequeue()}");

            Console.ReadLine();
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            Console.WriteLine(">>> Easy Queue <<<");

            EasyQueue <int> easyQueue = new EasyQueue <int>();

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

            Console.WriteLine(easyQueue.Dequeue());
            Console.WriteLine(easyQueue.Dequeue());
            Console.WriteLine(easyQueue.Dequeue());
            Console.WriteLine(easyQueue.Dequeue());
            Console.WriteLine(easyQueue.Peek());

            Console.ReadLine();

            Console.WriteLine(">>> Array Queue <<<");

            ArrayQueue <string> arrayQueue = new ArrayQueue <string>(3);

            arrayQueue.Enqueue("Никита");
            arrayQueue.Enqueue("Вика");
            arrayQueue.Enqueue("Алексей");

            Console.WriteLine(arrayQueue.Dequeue());
            Console.WriteLine(arrayQueue.Dequeue());
            Console.WriteLine(arrayQueue.Dequeue());

            Console.ReadLine();

            Console.WriteLine(">>> Linked Queue <<<");

            LinkedQueue <double> linkedQueue = new LinkedQueue <double>();

            linkedQueue.Enqueue(13.0);
            linkedQueue.Enqueue(26.0);
            linkedQueue.Enqueue(39.0);
            linkedQueue.Enqueue(52.0);

            Console.WriteLine(linkedQueue.Dequeue());
            Console.WriteLine(linkedQueue.Dequeue());
            Console.WriteLine(linkedQueue.Dequeue());
            Console.WriteLine(linkedQueue.Dequeue());

            Console.ReadLine();
            Console.WriteLine(">>> Easy Deque <<<");

            EasyDeque <int> easyDeque = new EasyDeque <int>();

            easyDeque.PushFront(1);
            easyDeque.PushFront(2);
            easyDeque.PushFront(3);
            easyDeque.PushFront(4);
            easyDeque.PushFront(5);
            easyDeque.PushFront(6);

            Console.WriteLine(easyDeque.PopFront());
            Console.WriteLine(easyDeque.PopFront());
            Console.WriteLine(easyDeque.PopBack());
            Console.WriteLine(easyDeque.PopBack());

            Console.ReadLine();
        }