typedef struct {
DataType data[MaxSize];
int top;
} LinearStack;
void initStack(LinearStack &stack) {
stack.top = -1;
}
void isEmpty(LinearStack stack) {
return stack.top == -1;
}
bool push(LinearStack &stack, DataType x) {
if(stack.top + 1 == MaxSize) {
return false;
}
stack.data[++stack.top] = x;
return true;
}
bool pop(LinearStack &stack, DataType &x) {
if(stack.top == -1) {
return false;
}
x = stack.data[stack.top--];
return true;
}
bool getTop(LinearStack &stack, DataType &x) {
if(stack.top == -1) {
return false;
}
x = stack.data[stack.top];
return true;
}