一些常用的数据结构(三):栈
继续。
三。栈
栈无非就是个从一端操作的线性表,LIFO,后进先出而已。
结构:
class Stack
{
public:
Stack(int siza=10);
~Stack(){delete[] element;}
privte:
int top;
int MaxSize;
int* element;
}
入栈:
Stack* Stack::Push(int x)
{
if(top==MaxSize)
//throw
element[++top]=x;
return *this;
}
出栈:
Stack* Stack::Push(int &x)
{
x = element[top--];
return *this;
}