C#队列(Queue)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace QueueTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Queue q = new Queue();

            q.Enqueue('A');
            q.Enqueue('M');
            q.Enqueue('G');
            q.Enqueue('W');

            Print(q);
            q.Enqueue('V');
            q.Enqueue('H');
            Print(q);

            Console.WriteLine("Removing some values ");
            char ch = (char)q.Dequeue();
            Console.WriteLine("The removed value: {0}", ch);
            ch = (char)q.Dequeue();
            Console.WriteLine("The removed value: {0}", ch);

            Print(q);
            Console.ReadKey();
        }

        static void Print(Queue q) 
        {
            Console.WriteLine("Current queue: ");
            foreach (char c in q)
            {
                Console.Write("{0} ", c);
            }
            Console.WriteLine();
        }
    }
}
C#队列(Queue)_第1张图片

你可能感兴趣的:(C#)