前田稔(Maeda Minoru)の超初心者のプログラム入門
![]()
![]()
class Stack<Type>
{
Type[] buf;
int top;
public Stack(int max)
{ this.buf = new Type[max];
this.top = 0;
}
public void Push(Type val)
{ this.buf[this.top++] = val;
}
public Type Pop()
{ return this.buf[--this.top];
}
public int Size
{ get { return this.top; }
}
public int MaxSize
{ get { return this.buf.Length; }
}
}
|
public static void Main()
{
const int SIZE = 5;
Stack<int> si = new Stack<int>(SIZE); // int 型でスタックを生成する
Stack<double> sd = new Stack<double>(SIZE); // double 型でスタックを生成する
for (int i = 1; i <= SIZE; i++)
{
si.Push(i);
sd.Push(1.0 / i);
}
while (si.Size != 0)
{
Console.Write("NO={0} 1/{0}={1}\n", si.Pop(), sd.Pop());
}
Console.ReadLine();
}
|
![]()