#ifndef _STACK_H
#define _STACK_H
class stack{
private:
enum {MAX = 10};
int num[MAX];
int SIZE;
public:
stack();
bool empty() const;
bool isfull() const;
bool push(const int &n);
bool pop(int &n);
void show();
};
#endif
#include<iostream>
#include"stack.h"
using namespace std;
stack::stack()
{
SIZE = 0;
}
bool stack::empty() const
{
if(SIZE == 0)
{
return true;
}
else{
return false;
}
}
bool stack::isfull() const
{
if(SIZE == MAX)
{
cout << SIZE << endl;
return true;
}
else{
return false;
}
}
bool stack::push(const int &n)
{
/*栈中还存在空间*/
if(!isfull())
{
num[SIZE] = n;
SIZE++;
return true;
}
/*栈满*/
else{
return false;
}
}
/*取出栈顶元素*/
bool stack::pop(int &n)
{
/*栈不为空*/
if(SIZE > 0 )
{
n = num[--SIZE];
return true;
}
else{
return false;
}
}
void stack::show()
{
for(int i=0; i<SIZE; i++)
{
cout << num[i] << endl;
}
}