点击查看代码
//Stack-array based implementation
#include<iostream>
using namespace std;
#define MAX_SIZE 101
int A[MAX_SIZE];//globle
int top = -1;//globle
void push(int x) {
if (top == MAX_SIZE - 1) {
cout << "error:stack overflow" << endl;
return;
}
A[++top] = x;
}
void pop() {
if(top ==- 1) {
cout << "error" << endl;
return;
}
top--;
}
void print() {
for (int i = 0; i <= top; i++) cout << A[i] << " ";
cout << endl;
}
int IsEmpty()
{
if (top == -1) return 1;
return 0;
}
int Top() {
return A[top];
}
int main() {
push(2); print();
push(5); print();
push(10); print();
pop(); print();
push(12); print();
}