配列運用のキュー
1602 ワード
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();
}
}
}