stack
#include<stdio.h>
#include<stdlib.h>
#define MaxSize 10
typedef struct{
int data[MaxSize];
int top;
}SqStack;
typedef struct {
int data[MaxSize];
int top0;
int top1;
}ShStack; //共享栈
void InitStack(SqStack &s)
{
s.top = -1; //指向当前数据元素
s.top = 0; //指向栈顶的下一项元素
}
bool StackEmpty(SqStack s) //判空
{
if(s.top == -1)
return true;
else
return false;
}
bool Push(SqStack &s , int x) //进栈
{
if(s.top == MaxSize - 1)
return false;
s.top = s.top + 1;
s.data[s.top] = x;
// s.data[ ++ s.top] = x; //等价于上面的
return true;
}
bool Pop(SqStack &s,int &x) //出栈
{
if(s.top == -1)
return false;
x = s.data[s.top];
s.top = s.top - 1;
// x = s.data[s.top--]; //等价于上面的
return true;
}
bool GetTop(SqStack s , int &x)
{
if(s.top == -1)
return false;
x = s.data[s.top];
return true;
}
int main()
{
SqStack s;
return 0;
}