Beispiel #1
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();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            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.PopFront());
            Console.WriteLine(linkedDeque.PopBack());
            Console.WriteLine(linkedDeque.PopBack());
            Console.WriteLine(linkedDeque.PopFront());

            Console.WriteLine();

            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.WriteLine();

            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();


            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();

            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();
        }
Beispiel #3
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();
        }
Beispiel #4
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();
        }
Beispiel #5
0
        public void menu()
        {
            var deque = new DuplexLinkedDeque<float>();

            void addDeque()
            {
                Console.WriteLine("Введите очередь: ");
                string str = Console.ReadLine();

                string[] strArr = str.Split(' ');
                foreach (var el in strArr)
                {
                    if (el != "")
                    {
                        deque.PushBack(Convert.ToInt32(el));
                    }
                }
            }

            void WriteDequeue()
            {
                Console.WriteLine("--------------");
                foreach (var el in deque)
                {
                    Console.Write(el + " ");
                }

                Console.WriteLine("");
                Console.WriteLine("--------------");

            }

            //deque.PushBack(1);
            //deque.PushBack(2);
            //deque.PushBack(3);
            //deque.PushBack(4);
            //deque.PushBack(5);
            //deque.PushBack(6);


            addDeque();
            WriteDequeue();

            while (true)
            {
                Console.WriteLine("11- Быстро добавить элементы Дека");
                Console.WriteLine("1- очистить дек (создать структуру пустой)");
                Console.WriteLine("2- проверить на пустоту");
                Console.WriteLine("3- Добавить елмент");
                Console.WriteLine("4- Взять елмент");
                Console.WriteLine("5- прочитать шестой элемент");
                Console.WriteLine("6- прочитать последний элемент");
                Console.WriteLine("7- записать третий элемент");
                Console.WriteLine("8- записать последний элемент");
                Console.WriteLine("66- Выйти");



                int menu = Convert.ToInt32(Console.ReadLine());
                int submenu = 0;
                int el = 0;
                switch (menu)
                {
                    case 11:
                        addDeque();
                        break;
                    case 1:
                        deque.ClearDeq();
                        break;
                    case 2:
                        if (deque.Count == 0)
                            Console.WriteLine("Дек пустой");
                        else
                            Console.WriteLine($"Дек имеет {deque.Count} елментов");
                        break;
                    case 3:
                        Console.WriteLine("0- В начало");
                        Console.WriteLine("1- В конец");
                        submenu = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine("Введите елмент");
                        el = Convert.ToInt32(Console.ReadLine());
                        if (submenu == 0)
                            deque.PushFront(el);
                        else
                            deque.PushBack(el);
                        break;
                    case 4:
                        Console.WriteLine("0- С начала");
                        Console.WriteLine("1- С конца");
                        submenu = Convert.ToInt32(Console.ReadLine());
                        if (submenu == 0)
                            Console.WriteLine($"Результат: {deque.PopFront()}");
                        else
                            Console.WriteLine($"Результат: {deque.PopBack()}");
                        break;

                    case 5:
                        if (deque.Count < 6)
                            Console.WriteLine("Дек имеет меньше 6 елементов");
                        else
                            Console.WriteLine($"Результат {deque.GetSixs()}");
                        break;
                    case 6:
                        Console.WriteLine($"Результат: {deque.PeekBack()}");
                        break;
                    case 7:
                        Console.WriteLine("Введите елмент");
                        el = Convert.ToInt32(Console.ReadLine());
                        deque.SetThird(el);
                        break;

                    case 8:
                        Console.WriteLine("Введите елмент");
                        el = Convert.ToInt32(Console.ReadLine());
                        deque.SetTail(el);
                        break;
                    case 66:
                        Console.Clear();
                        return;
                    default:
                        break;
                }

                WriteDequeue();

            }
        }