C
源程序 栈的实现
//
栈的实现
//供学习 c++人员使用
#define STACK_SIZE 10000
//宏定义
#include<iostream>
//头文件
using namespace std;
template<class elemtype>
struct node
{
elemtype data;
//数据域
node<elemtype>*next;
//指针域
node(){next=NULL;}
//无参数的的构造函数
node(elemtype item,node<elemtype>*link=NULL)//已知数据元素值和指针建
立结点
{
data=item;
next=link;
}
};
template<class elemtype>
class stack
{
public:
stack(){}
//构造函数
virtual ~stack(){}
//析构函数
virtual bool push(const elemtype &e)=0; //入栈
virtual bool pop(elemtype &e)=0;
//出栈
virtual bool gettop(elemtype &e)const=0;//取栈顶元素
};
//顺序栈类模板
template<class elemtype>