关于C# 队列 Queue

关于C# 队列 Queue

using System.Collections;

       static void Main(string[] args)
        {
            TestQueue();
        }

        //------------------------------------------------------
        // 队列(Queue)

        public static void TestQueue()
        {
            Queue q = new Queue();

            q.Enqueue('A');
            q.Enqueue('B');
            q.Enqueue('C');
            q.Enqueue('D');

            Console.WriteLine("当前队列e: ");
            foreach (char c in q)
                Console.Write(c + " ");
            Console.WriteLine();

            q.Enqueue('E');
            q.Enqueue('F');

            Console.WriteLine("当前队列: ");
            foreach (char c in q)
                Console.Write(c + " ");

            Console.WriteLine();
            Console.WriteLine("开始出队 ");
            char ch = (char)q.Dequeue();
            Console.WriteLine("出队: {0}", ch);
            ch = (char)q.Dequeue();
            Console.WriteLine("出队: {0}", ch);
            Console.ReadKey();
            Console.ReadLine();
        }
        //------------------------------------------------------

 

发表回复

您的电子邮箱地址不会被公开。