/**
* 作者: LinX 2017-6-15
*
* 内容: 顺序栈的结构以及基本操作
*
*/
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 100
typedef int ElemType;
typedef struct SqStack
{
ElemType data[MAXSIZE];
int top;
}SqStack;
/*栈的基本操作*/
SqStack* InitStack(); //初始化栈
void push(SqStack *S,ElemType e); //压栈
ElemType pop(SqStack *S); //弹栈
int stackEmpty(SqStack *S); //判空
int stackFull(SqStack *S); //判满
void printStack(SqStack *S); //打印栈中元素
int main()
{
SqStack *S = InitStack();
push(S,1);
push(S,2);
push(S,3);
push(S,4);
printStack(S);
printf("%d ",pop(S));
printf("%d ",pop(S));
printf("%d ",pop(S));
printf("%d ",pop(S));
printf("%d",pop(S));
printf("%d",pop(S));
return 0;
}
/*初始化栈*/
SqStack* InitStack()
{
SqStack *S = (SqStack *) malloc (sizeof(SqStack));
S->to
栈的结构及其操作
最新推荐文章于 2022-03-01 13:10:27 发布