链栈
废话不多说,直接上代码实现。
#include <iostream>
#define OK 1
#define ERROR 0
using namespace std;
typedef int SElemType;
typedef int Status;
typedef struct StackNode
{
SElemType data;
struct StackNode *next;
}StackNode, *LinkStack;
//初始化链栈
Status InitList(LinkStack &S)
{
S=NULL; //构造一个空栈S,栈顶指针置空
return OK;
}
//入栈
Status Push (LinkStack &S, SElemType e)
{
StackNode *p; int n;
cout <<"请输入入栈元素个数:";
cin>>n;
cout <<"输入入栈元素为:";
for (int i=0; i<n; i++)
{
cin >>e;
p