链栈的实现
# include<stdio.h>
# define OK 1
# define ERROR 0
# define TRUE 1
# define FALSE 0
typedef int Status;
typedef int SElemType;
typedef struct StackNode{
SElemType data;
struct StackNode *next;
}StackNode,*LinkStack;
// 1、栈的初始化
Status InitLinkStack(LinkStack &S){
S = NULL;
return OK;
}
// 2、链栈是否为空
Status LinkStackEmpty(LinkStack &S){
if(S == NULL){
return TRUE;
}else{
return FALSE;
}
}
// 3、 链栈的入栈
Status Push(LinkStack &S,SElemType e){
StackNode *p;
p = new StackNode;
p->data = e;
p->next = S;
S = p;
return OK;
}
// 4、链栈的出栈
Status Pop(LinkStack &S,SElemType e){
StackNode *p;
if(S == NULL){
return ERROR;
}
e = S->data;
p = S;
S = S->next;
delete p;
return OK;
}
// 5、取栈顶元素
SElemType GetTop(LinkStack S){
if(S != NULL){
return S->data;
}
}
int main(){
LinkStack S;
InitLinkStack(S);
return 0;
}