예제 #1
0
파일: Program.cs 프로젝트: A9dr8weed/Queue
        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());
        }
예제 #2
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 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.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();
        }
예제 #3
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();
        }
예제 #4
0
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("Queue implementation with C# by @zygabyte");

                Console.WriteLine("_____________ArrayQueue Implementation_____________");
                var arrayQueue = new ArrayQueue <string>(10);
                Console.WriteLine("Initial queue");
                arrayQueue.Enqueue("first");
                arrayQueue.Enqueue("second");
                arrayQueue.Enqueue("third");
                arrayQueue.Enqueue("fourth");
                arrayQueue.Enqueue("fifth");
                arrayQueue.Enqueue("sixth");
                arrayQueue.Enqueue("seventh");
                arrayQueue.Enqueue("eighth");

                arrayQueue.PrintQueue();

                Console.WriteLine("Is Queue empty? ");
                Console.WriteLine(arrayQueue.IsEmpty());
                Console.WriteLine();

                Console.WriteLine("First element in queue");
                Console.WriteLine(arrayQueue.First());

                Console.WriteLine("\nDequeuing...");
                arrayQueue.Dequeue();
                arrayQueue.PrintQueue();

                Console.WriteLine("Dequeuing...");
                arrayQueue.Dequeue();
                arrayQueue.PrintQueue();

                Console.WriteLine("Dequeuing...");
                arrayQueue.Dequeue();
                arrayQueue.PrintQueue();

                Console.WriteLine("Enqueuing...");
                arrayQueue.Enqueue("random dude");
                arrayQueue.PrintQueue();

                Console.WriteLine("Dequeuing...");
                arrayQueue.Dequeue();
                arrayQueue.PrintQueue();

                Console.WriteLine("Dequeuing...");
                arrayQueue.Dequeue();
                arrayQueue.PrintQueue();

                Console.WriteLine("Dequeuing...");
                arrayQueue.Dequeue();
                arrayQueue.PrintQueue();

                Console.WriteLine("Dequeuing...");
                arrayQueue.Dequeue();
                arrayQueue.PrintQueue();

                Console.WriteLine("Dequeuing...");
                arrayQueue.Dequeue();
                arrayQueue.PrintQueue();

                Console.WriteLine("Dequeuing...");
                arrayQueue.Dequeue();
                arrayQueue.PrintQueue();

                Console.WriteLine("Is Queue empty? ");
                Console.WriteLine(arrayQueue.IsEmpty());
                Console.WriteLine();

                Console.WriteLine("Enqueuing again");
                arrayQueue.Enqueue("1");
                arrayQueue.Enqueue("second");
                arrayQueue.Enqueue("3");
                arrayQueue.Enqueue("fourth");
                arrayQueue.Enqueue("5");
                arrayQueue.Enqueue("sixth");
                arrayQueue.Enqueue("7");
                arrayQueue.Enqueue("8");
                arrayQueue.Enqueue("9");
                arrayQueue.Enqueue("10");
                arrayQueue.PrintQueue();
                Console.WriteLine("_____________End ArrayQueue Implementation_____________");
                Console.WriteLine();



                Console.WriteLine("_____________LinkedQueue Implementation_____________");
                var linkedQueue = new LinkedQueue <string>();
                Console.WriteLine("Initial queue");
                linkedQueue.Enqueue("first");
                linkedQueue.Enqueue("second");
                linkedQueue.Enqueue("third");
                linkedQueue.Enqueue("fourth");
                linkedQueue.Enqueue("fifth");
                linkedQueue.Enqueue("sixth");
                linkedQueue.Enqueue("seventh");
                linkedQueue.Enqueue("eighth");

                linkedQueue.PrintQueue();

                Console.WriteLine("Is Queue empty? ");
                Console.WriteLine(linkedQueue.IsEmpty());
                Console.WriteLine();

                Console.WriteLine("First element in queue");
                Console.WriteLine(linkedQueue.First());

                Console.WriteLine("\nDequeuing...");
                linkedQueue.Dequeue();
                linkedQueue.PrintQueue();

                Console.WriteLine("Dequeuing...");
                linkedQueue.Dequeue();
                linkedQueue.PrintQueue();

                Console.WriteLine("Dequeuing...");
                linkedQueue.Dequeue();
                linkedQueue.PrintQueue();

                Console.WriteLine("Enqueuing...");
                linkedQueue.Enqueue("random dude");
                linkedQueue.PrintQueue();

                Console.WriteLine("Dequeuing...");
                linkedQueue.Dequeue();
                linkedQueue.PrintQueue();

                Console.WriteLine("Dequeuing...");
                linkedQueue.Dequeue();
                linkedQueue.PrintQueue();

                Console.WriteLine("Dequeuing...");
                linkedQueue.Dequeue();
                linkedQueue.PrintQueue();

                Console.WriteLine("Dequeuing...");
                linkedQueue.Dequeue();
                linkedQueue.PrintQueue();

                Console.WriteLine("Dequeuing...");
                linkedQueue.Dequeue();
                linkedQueue.PrintQueue();

                Console.WriteLine("Dequeuing...");
                linkedQueue.Dequeue();
                linkedQueue.PrintQueue();

                Console.WriteLine("Is Queue empty? ");
                Console.WriteLine(linkedQueue.IsEmpty());
                Console.WriteLine();

                Console.WriteLine("Enqueuing again");
                linkedQueue.Enqueue("1");
                linkedQueue.Enqueue("second");
                linkedQueue.Enqueue("3");
                linkedQueue.Enqueue("fourth");
                linkedQueue.Enqueue("5");
                linkedQueue.Enqueue("sixth");
                linkedQueue.Enqueue("7");
                linkedQueue.Enqueue("8");
                linkedQueue.Enqueue("9");
                linkedQueue.Enqueue("10");
                linkedQueue.PrintQueue();
                Console.WriteLine("_____________End LinkedQueue Implementation_____________");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }