#include<iostream>
using namespace std;
#define MAXSIZE 100
typedef int SElemType;
typedef struct {
SElemType* base;
SElemType* top;
int stacksize;
}SqStack;//顺序栈
//构造一个空栈
int InitStack(SqStack& s) {
s.base = new SElemType(MAXSIZE);
if (!s.base) {
exit(OVERFLOW);
}
s.top = s.base;
s.stacksize = MAXSIZE;
return 1;
}
//判断顺序栈是否为空
int StackEmpty(SqStack s) {
if (s.top == s.base) {
return true;
}
return false;
}
//求顺序栈长度
int StackEmpty(SqStack s) {
if (s.top == s.base)return true;
return false;
}
//求顺序栈长度
int StackLength(SqStack s) {
return s.top - s.base;
}
int ClearStack(SqStack s) {
if (s.base)
s.top = s.base;
return 1;
}
//销毁顺序栈,释放这块空间
int DestoryStack(SqStack& s) {
if (s.base) {
delete s.base;
s.stacksize = 0;
s.base = s.top = NULL;
}
}
//顺序栈入栈
int push(SqStack& s, SElemType e) {
if (s.top - s.base == s.stacksize)return 0;
*s.top = e;
s.top++;
return 1;
}
//顺序栈的pop
int pop(SqStack& s, SElemType& e) {
if (s.top == s.base)return 0;
--s.top;
e = *s.top;
return 1;
}
int main() {
return 0;
}
链栈
#include<iostream>
using namespace std;
typedef struct StackNode {
int data;
struct StackNode* next;
}StackNode,*LinkStack;
void InitStaack(LinkStack& s) {
s = NULL;
return;
}
bool StackEmpty(LinkStack s) {
if (s == NULL)return true;
return false;
}
//链栈的入栈
int push(LinkStack& s, int e) {
LinkStack p = new StackNode;
p->data = e;
p->next = s;
s = p;
return 1;
}
int pop(LinkStack& s, int& e) {
if (s = NULL) {
return 0;
}
e = s->data;
LinkStack p = s;
s = s->next;
delete p;
return 1;
}
int getTop(LinkStack s) {
if (s != NULL)return s->data;
}
int main() {
return 0;
}