#include<stdio.h>
#define MaxSize 20
typedef int ElemType;
typedef struct {
ElemType data[MaxSize];
int top;
}SqStack;
void InitSqStack(SqStack& S) {
S.top = -1;
}
bool Push(SqStack& S,ElemType e) {
if (S.top == MaxSize - 1) return false;
S.data[++S.top] = e;
return true;
}
bool Pop(SqStack& S, ElemType &e) {
if (S.top == -1) return false;
e = S.data[S.top--];
return true;
}
bool GetTop(SqStack& S, ElemType &e) {
if (S.top == -1) return false;
e = S.data[S.top];
return true;
}
int main() {
SqStack S;
InitSqStack(S);
ElemType e=6;
Push(S, e);
e = 7;
Push(S, e);
e = 2;
GetTop(S, e);
printf("%d", e);
Pop(S, e);
printf("%d", e);
Pop(S, e);
printf("%d", e);
return 0;
}
数据结构(C/C++)——顺序栈
最新推荐文章于 2024-08-18 17:28:15 发布