/*
带头结点的链栈的操作集中包含的操作
1、初始化链栈S
Status InitStack_LS(LStack &S);
2、销毁链栈S
Status DestroyStack_LS(LStack &S);
3、判断链栈S是否为空
Status StackEmpty_LS(LStack S);
4、清空链栈 S
Status ClearStack_LS(LStack &S);
5、入栈操作
Status Push_LS(LStack &S,ElemType e);
6、出栈操作
Status Pop_LS(LStack &S,ElemType &e);
7、读取栈顶元素,并用 e 返回
Status GetTop_LS(LStack S, ElemType &e);
*/
#include<stdio.h>
#include<stdlib.h>
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define OVERFLOW -1
#define PERROR 2
typedef int Status;
// 数据元素的类型,使用时需根据问题的需求定义。
typedef int ElemType;
typedef struct LSNode{
ElemType data; // 数据域
struct LSNode* next; // 指针域
}LSNode,*LStack; // 结点和链栈类型
// 1、初始化链栈S
Status InitStack_LS(LStack &S){
S = (LSNode*)malloc(sizeof(LSNode)); // 为头结点申请空间
if(S==NULL){
return OVERFLOW; // 申请失败,返回
}
S->next = NULL; // 为头结点的指针域赋初值
return OK; // 初始化成功,返回
}
// 2、销毁链栈S
Status DestroyStack_LS(LStack &S){
if(S==NULL)return PERROR