实验代码:
#include<iostream>
using namespace std;
const int max = 10;
class SeqStack {
int data[max];
int top;
public:
SeqStack() { top = -1; }
void push(int);
void pop();
int gettop() { if (top != -1)return data[top]; }
int empty() { if (top == -1)return 1; else return 0; }
};
void SeqStack::push(int x) {
if (top == max - 1)throw"overflow";
data[++top] = x;
}
void SeqStack::pop() {
while (empty() != 1) {
cout << data[top--];
}cout << endl;
}
void main() {
SeqStack p;
p.push(1); p.push(2); p.push(3); p.push(4); p.push(5);
p.pop();
}
运行结果: