#pragma once
#include
#include
//这里表示的是顺序栈(Sequence Stack)
class Seqstack {
private:
int maxsize;
int* base;
int top;
public:
Seqstack(int size);
~Seqstack();
void push(int n);
int pop();
int Gettop();
bool Isempty();
void removeall();
};
Seqstack::Seqstack(int size) {
maxsize = size;
base = new int[maxsize];
if (base == NULL) throw"wrong parameter";
top = -1;
}
Seqstack::~Seqstack() {
delete base;
}
void Seqstack::push(int n) {
if (top == maxsize-1)throw"wrong parameter";
top++;
base[top] = n;
}
int Seqstack::pop() {
if (top == -1)throw"wrong parameter";
return base[top–];
}
bool Seqstack::Isempty() {
if (top == -1)return true;
else return false;
}
int Seqstack::Gettop() {
return base[top];
}
void Seqstack::removeall() {
while (top > -1)
{
std::cout << this->pop()<<std::endl;
}
}
//简单的主函数
#include"Sstack.h"
int main()
{
Seqstack ll(5); int k;
std::cout << "输入3个栈的数字: ";
for (int i = 0; i < 3; i++)
{
std::cin >> k;
ll.push(k);
}
ll.removeall();
system(“pause”);
return 0;
}