头文件:
#pragma once
#include <iostream>
#include <assert.h>
#include <string>
using namespace std;
template<class Type>
class SeqStack
{
public:
SeqStack(size_t sz = INIT_SZ);
~SeqStack();
public:
bool empty()const;
bool full()const;
void show()const;
bool push(const Type &x);
bool pop();
void gettop(Type &x);
int length()const;
void clear();
void destory();
void quit_system(Type &x);
private:
enum{ INIT_SZ = 64 };
Type *base;
int capacity;
int top;
};
template<class Type>
SeqStack<Type>::SeqStack(size_t sz = INIT_SZ)
{
capacity = sz > INIT_SZ ? sz : INIT_SZ;
base = new Type[capacity];
assert(base != NULL);
top = 0;
}
template<class Type>
SeqStack<Type>::~SeqStack()
{
destory();
}
// 判断栈是否满了
template<class Type>
bool SeqStack<Type>::full()const
{
return (top >= capacity);
}
// 判断是否