using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace Queue_test
{
class Program
{
static void Main()
{
Queue qu1 = new Queue();
Queue qu2=new Queue();
foreach (int i in new int[4] { 1, 2, 3, 4 })
{
qu1.Enqueue(i); //入队
qu2.Enqueue(i);
}
foreach (int i in qu1)
{
Console.WriteLine(i);//遍历
}
qu1.Dequeue(); //出队
Console.WriteLine("Dequeue");
foreach (int i in qu1)
{
Console.WriteLine(i);
}
qu2.Peek(); //返回位于queue开始处的对象,但不将其移除
qu2.Peek();
Console.WriteLine("Peek");
foreach (int i in qu2)
{
Console.WriteLine(i);
}
}
}
}
C#之队列学习案例
本文转载:CSDN博客