Пример #1
0
        static void Main(string[] args)
        {
            LinkedQueue <int> lq = new LinkedQueue <int>();

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

            Console.WriteLine(string.Join(", ", lq));
            lq.Dequeue();
            Console.WriteLine(string.Join(", ", lq));
            lq.Dequeue();
            Console.WriteLine(string.Join(", ", lq));
        }
        //13.Implement the ADT queue as dynamic linked list. Use generics (LinkedQueue<T>)
        //to allow storing different data types in the queue

        static void Main()
        {
            LinkedQueue <int> myQueue = new LinkedQueue <int>();

            for (int i = 0; i < 10; i++)
            {
                myQueue.Enqueue(i);
            }

            Console.WriteLine("The queue: " + string.Join(", ", myQueue));

            var dequeuedElement = myQueue.Dequeue();
            var peekedElement   = myQueue.Peek();

            Console.WriteLine("Dequeued element: " + dequeuedElement);
            Console.WriteLine("Peeked element: " + peekedElement);
            Console.WriteLine("The new queue: " + string.Join(", ", myQueue));
        }
Пример #3
0
        public static void Main()
        {
            var linkedQueue = new LinkedQueue <string>();
            var firstItem   = "TestItem 1";
            var secondItem  = "TestItem 2";
            var thirdItem   = "TestItem 3";

            linkedQueue.Enqueue(firstItem);
            linkedQueue.Enqueue(secondItem);
            linkedQueue.Enqueue(thirdItem);

            var firstListItem = linkedQueue.Peek();

            Console.WriteLine("First element neightbour --- " + firstListItem.NextItem.Value);

            var removedItem = linkedQueue.Dequeue();

            Console.WriteLine("Removed item --- " + removedItem.Value);
        }
Пример #4
0
        static void Main(string[] args)
        {
            var queue = new LinkedQueue <int>();

            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);
            queue.Enqueue(4);
            queue.Enqueue(5);
            queue.Enqueue(6);
            queue.Enqueue(7);
            Console.WriteLine("Count: " + queue.Count);
            Console.WriteLine(string.Join(", ", queue));
            Console.WriteLine("Removed item: {0}", queue.Dequeue());
            Console.WriteLine("Count: " + queue.Count);
            Console.WriteLine(string.Join(", ", queue));
            Console.WriteLine("Clearing queue");
            queue.Clear();
            Console.WriteLine(string.Join(", ", queue));
        }