Dequeue and Peek : Queue « Data Structure « C# / CSharp Tutorial






using System;
using System.Collections.Generic;

    public class Tester
    {
        static void Main()
        {
            Queue<Int32> intQueue = new Queue<Int32>();
            for (int i = 0; i < 5; i++)
            {
                intQueue.Enqueue(i * 5);
            }
            PrintValues(intQueue);
            Console.WriteLine("\n(Dequeue)\t{0}", intQueue.Dequeue());
            Console.Write("intQueue values:\t");
            PrintValues(intQueue);
            Console.WriteLine("\n(Dequeue)\t{0}", intQueue.Dequeue());
            PrintValues(intQueue);
            Console.WriteLine("\n(Peek) \t{0}", intQueue.Peek());
            Console.Write("intQueue values:\t");
            PrintValues(intQueue);
        }

        public static void PrintValues(IEnumerable<Int32> myCollection)
        {
            IEnumerator <Int32> myEnumerator = myCollection.GetEnumerator();
            while (myEnumerator.MoveNext())
                Console.Write("{0} ", myEnumerator.Current);
         }
    }








11.38.Queue
11.38.1.Enqueue and dequeue
11.38.2.Clear a Queue
11.38.3.Peek a queue
11.38.4.Creating a list from a queue
11.38.5.Dequeue and Peek
11.38.6.Queue<(Of <(T>)>) generic class, including the ToArray method.
11.38.7.Queue<(Of <(T>)>) generic class, the Dequeue method.