//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));
        }
Exemplo n.º 2
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);
        }