//Queue用法
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Queue qu = new Queue();
Queue qu2 = new Queue();
foreach (int i in new int[4] { 1, 2, 3, 4 })
{
qu.Enqueue(i);//填充
qu2.Enqueue(i);
}
foreach (int i in qu)
{
Console.WriteLine(i);//遍历
}
qu.Dequeue();
Console.WriteLine("Dequeue");
foreach (int i in qu)
{
Console.WriteLine(i);
}
qu2.Peek();//弹出最后一项不删除
Console.WriteLine("Peek");
foreach (int i in qu2)
{
Console.WriteLine(i);
}
while (qu2.Count != 0)
{
int i = (int)qu2.Dequeue();//清空
qu2.Dequeue();//清空
}
Console.WriteLine("清空");
foreach (int i in qu2)
{
Console.WriteLine(i);
}
}
}
}