using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
/*泛型栈*/
namespace ExGeneric
{
class MyStack<T>
{
const int MaxStack = 10;
T[] StackArrray;
public MyStack()
{
StackArrray = new T[MaxStack];
}
bool IsStackFull
{
get { return StackPointer >= MaxStack; }
}
bool IsStackEmpty
{
get { return StackPointer <= 0; }
}
int StackPointer = 0;
public void Push(T x)
{
if (!IsStackFull)
{
StackArrray[StackPointer++] = x;
}
}
public T Pop()
{
return (!IsStackEmpty) ? StackArrray[--StackPointer] : StackArrray[0];
}
public void Print()
{
for (int i = StackPointer - 1; i > 0; i--)
{
Console.WriteLine(" Value:{0}",StackArrray[i]);
}
}
}
class Program
{
static void Main(string[] args)
{
var stackInt = new MyStack<int>();
var stackString = new MyStack<string>();
stackInt.Push(3);
stackInt.Push(4);
stackInt.Push(7);
stackInt.Print();
stackString.Push("asd");
stackString.Push("dfb");
stackString.Push("bdb");
stackString.Print();
}
}
}