C语言数据结构之栈的基本操作,栈的各种操作
C语言数据结构之栈的基本操作
一.程序结构图
二
.算法及其功能函数
InitStack(SqStack *S)
/*创建栈*/
GetTop(SqStack *S,SElemType e) /*取栈顶元素并用e返回*/ Push(SqStack *S,SElemType e) /*插入e为栈顶元素*/ Pop(SqStack *S,SElemType *e) /*删除栈顶元素并用e返回*/ StackEmpty(SqStack S) /*判断栈是否为空*/ StackLength(SqStack S) /*求栈的长度*/ Nizhi(SqStack S) /*将栈中元素逆置*/ 三.源代码
#include
#include
#define OK 1
#define OVERFLOW -2
typedef int Status;
typedef int SElemType;
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
typedef struct{
SElemType *base;
SElemType *top;
int stacksize;
}SqStack;
Status InitStack(SqStack *S)
{
int i,n; SElemType e;