数据结构栈的实现

//
// Created by XuYiMing on 2020/2/21.
//

#include <iostream>

using namespace std;
#define MaxSize 50
typedef int ElementType;

//*********************顺序栈*****************
typedef struct {
ElementType data[MaxSize];
int top;
} SqStack;

void InitStack(SqStack &s) { //栈初始化
s.top = -1;
}

bool StackEmpty(SqStack &s) { //栈判空
if (s.top == -1)
return true;
else
return false;
}

bool PushStack(SqStack &s, ElementType x) { //进栈
if (s.top + 1 == MaxSize)
return false;
s.data[++s.top] = x;
return true;
}

bool PopStack(SqStack &s, ElementType &x) { //出栈
if (s.top == -1)
return false;
x = s.data[s.top--];
return true;
}

bool GetTop(SqStack s, ElementType &x) { //读栈顶元素
if (s.top == -1)
return false;
x = s.data[s.top];
return true;
}

//*****************链栈******************
typedef struct LinkNode {
ElementType data;
struct LinkNode *next;
} *LiStack;


int main() {

return 0;
}