using System;
using System.Collections.Generic;
using System.Text;
namespace Queue
{
class QueueTest//队列类
{
int[] array;
int length = 0;//保存元素个数,初始化为0
public QueueTest(int num) {
array = new int[num];//数组分配空间
}
public int Length {//只读属性读取当前队列的元素个数
get {
return this.length;
}
}
public void Push(int num) { //数据进队列方法
if (length > 0)
{
for (int i = length - 1; i >= 0; i--)
{
array[i+1] = array[i];
}
}
array[0] = num;
length++;
}
public int Pop() {
//return array[--length];
return array[--length];
}
}
class Test {
static void Main(string[] args) {
QueueTest qt = new QueueTest(100);
qt.Push(1);//往队列里放入几个数
qt.Push(2);
qt.Push(3);
qt.Push(4);
while (qt.Length > 0) {//取出所有数
Console.Write(qt.Pop() + "\t");
}
Console.Read();
}
}
}