#include <stdio.h>
#include <stdbool.h>
#define MaxSize 20
typedef struct {
int data[MaxSize];//数组
int top;//栈顶
}SqStack;//顺序栈存储类型
void InitStack(SqStack s) {
s.top = -1;
}//初始化
bool StackEmpty(SqStack s) {
if (s.top != 1) {
return false;
}
else
return true;
}//判空
bool push(SqStack s, int x) {
if (s.top == MaxSize - 1) {
return false;//栈已满
}
else {
s.data[s.top + 1] = x;
s.top = s.top + 1;
//s.data[++s.top]=x;
}
return true;
}//进栈
bool pop(SqStack s, int x) {
if (s.top == -1) {
return false;
}
else
s.data[s.top--] = x;
return true;
}//出栈
C语言栈的基本操作
最新推荐文章于 2023-08-22 15:39:33 发布