public static void Main()
        {
            var queue = new Queue<int>();

            Console.WriteLine("Adding 1,2,3,4,5");
            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);
            queue.Enqueue(4);
            queue.Enqueue(5);

            Console.WriteLine("Peeking first added number: {0}", queue.Peek());
            Console.WriteLine("Dequeuing number: {0}", queue.Dequeue());
            Console.WriteLine("Dequeuing number: {0}", queue.Dequeue());
            Console.WriteLine("Peeking number: {0}", queue.Peek());

            Console.WriteLine("Enqueueing number 6");
            queue.Enqueue(6);

            Console.WriteLine("Peeking number: {0}", queue.Peek());
        }
예제 #2
0
        public static void Main()
        {
            var queue = new Queue<int>();

            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);
            queue.Enqueue(4);

            var count = queue.Count;
            for (int i = 0; i < count; i++)
            {
                Console.WriteLine(queue.Peek());
                queue.Dequeue();
            }
        }
예제 #3
0
        public static void Main(string[] args)
        {
            Queue<int> numbers = new Queue<int>();
            Console.WriteLine(numbers);
            numbers.Enqueue(1);
            Console.WriteLine(numbers);

            // numbers.Dequeue();
            // Console.WriteLine(numbers);
            // numbers.Dequeue();
            // Console.WriteLine(numbers);
            numbers.Enqueue(2);
            Console.WriteLine(numbers);
            numbers.Dequeue();
            Console.WriteLine(numbers);
            numbers.Enqueue(1);
            Console.WriteLine(numbers);
            numbers.Enqueue(3);
            Console.WriteLine(numbers);
            numbers.Enqueue(4);
            Console.WriteLine(numbers);
            numbers.Enqueue(5);
            Console.WriteLine(numbers);
            numbers.Enqueue(6);
            Console.WriteLine(numbers);

            Console.WriteLine(numbers.Dequeue());
            Console.WriteLine(numbers);
            Console.WriteLine(numbers.Dequeue());
            Console.WriteLine(numbers);
            Console.WriteLine(numbers.Dequeue());
            Console.WriteLine(numbers);

            numbers.TrimExcess();
            Console.WriteLine(numbers);
            Console.WriteLine(numbers.Dequeue());
            Console.WriteLine(numbers);
            Console.WriteLine(numbers.Dequeue());
            Console.WriteLine(numbers);
            Console.WriteLine(numbers.Dequeue());
            Console.WriteLine(numbers);

            // numbers.Enqueue(6);
            // Console.WriteLine(numbers);
        }