using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace QueueDemo
{
class Program
{
static void Main(string[] args)
{
//1.元素采用先入先出机制,元素只能被添加到队尾(称为入队),不允许在中间的某个位置插入
//2.只有队头的元素才能被删除(称为出队),不允许直接对队列中的非队头元素进行删除,从而保证FIFO机制
//3.不允许直接对队列中非队头元素进行访问。
string[] people = new string[]{"黑人","白人","黄种人"};
Queue<string> queue = new Queue<string>();
Console.WriteLine("1、模拟开始入队列");
foreach (string str in people)
{
Console.WriteLine("{0}--入队", str);
queue.Enqueue(str);
}
Console.ReadLine();
Console.WriteLine("2、模拟出队");
while (queue.Count > 0)
{
string p = queue.Dequeue();
Console.WriteLine("{0} -出队", p);
}
Console.ReadLine();
}
}
}
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace QueueDemo
{
class Program
{
static void Main(string[] args)
{
//1.元素采用先入先出机制,元素只能被添加到队尾(称为入队),不允许在中间的某个位置插入
//2.只有队头的元素才能被删除(称为出队),不允许直接对队列中的非队头元素进行删除,从而保证FIFO机制
//3.不允许直接对队列中非队头元素进行访问。
string[] people = new string[]{"黑人","白人","黄种人"};
Queue<string> queue = new Queue<string>();
Console.WriteLine("1、模拟开始入队列");
foreach (string str in people)
{
Console.WriteLine("{0}--入队", str);
queue.Enqueue(str);
}
Console.ReadLine();
Console.WriteLine("2、模拟出队");
while (queue.Count > 0)
{
string p = queue.Dequeue();
Console.WriteLine("{0} -出队", p);
}
Console.ReadLine();
}
}
}