//【数据结构】用C++编写栈及基本操作(包括入栈,出栈,获得栈顶,摧毁,清空等等)
//头文件
#ifndef _SEQ_STACK_
#define _SEQ_STACK_
#include <iostream>
using namespace std;
template <class Type>
class SeqStack
{
public:
SeqStack(size_t sz=INIT_SIZE)
{
capacity = sz > INIT_SIZE ? sz : INIT_SIZE;
base = new Type[capacity];
top = 0;
}
~SeqStack()
{
destory();
}
public:
bool empty() const //判断是否为空
{
return(top == 0);
}
bool full()const //判断是否已满
{
return(top >= capacity);
}
void push(const Type &x) //进栈
{
if (full() )
{
cout << "栈已满,不能插入。" << endl;
return;
}
base[top++] = x;
}
void pop() //出栈
{
top--;
}
bool getTop(Type &x) const //获得栈顶
{
if (top == 0)
return false;
x = base[top - 1];
return true;
}
int length() const //求大小
{
return top;
}
void clear() //清除
{