LIFO 栈结构

 typedef  int ElemenType;
struct seqStack{
ElemeType data[MaxSize];
int top;
};
typedef struct seqStack* Stack;

LIFO 栈基本操作

 //LIFO 顺序栈 初始化
void InitStack(Stack s){
s -> top = -;
} //LIFO 顺序栈判断栈空
boolean StackEmpty(Stack s){
if(s -> top == -) return true;
else return false;
} //LIFO 顺序栈判断栈满
boolean StackFull(Stack s){
if(s -> top == MaxSize-) return true;
else return false;
} //LIFO 顺序栈进栈
void Push(Stack s, ElemType x){
if(s->top == MaxSize-){
printf("栈满溢出错误!\n");
exit();
}
s -> top++;
s -> data[s>top] = x;
} //LIFO 顺序栈出栈
ElemType Pop(Stack s){
if(StackEmpty(s){
printf("栈下溢错误!\n");
exit();
}
x = s->data[s->top];
s -> top--;
return x;
} //LIFO 顺序栈读取栈顶元素
ElemType GetTop(Stack s){
if(StackEmpty(s){
printf("下溢错误!\n");
exit();
}
return s -> data[s -> top];
}
05-11 13:13