namespace Stack
{
public partial class Stack: System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Stack<int> a = new Stack<int>(100);
a.Push(10);
a.Push(8888);
int x = a.Pop();
a.Push(1230);
}
}
public class Stack<T>
{
private int CurrentIndex = 0;
private T[] m_item;
public T Pop() { CurrentIndex = CurrentIndex - 1; return m_item[CurrentIndex - 1]; }
public void Push(T item) { m_item[CurrentIndex] = item; CurrentIndex = CurrentIndex + 1; }
public Stack(int i)
{
this.m_item = new T[i];
}
}
}
泛型实现栈
最新推荐文章于 2022-11-05 14:14:47 发布