昨天刚刚过了二十岁生日,决定今天开始开始写博客,记录自己的成长,同时也为了以后复习用。回归正题,先上代码
#include<iostream>
#include<cctype>
using namespace std;
typedef double Stack_entry;
const int maxstack = 10;
enum Error_code{ sucess, overflow, underflow };
typedef double Stack_entry;
class Stack
{
public:
Stack();
bool empty()const;//如果Stack为空,返回true,否则返回false
Error_code pop();//如果Stack非空,删除栈顶元素,如Stack为空,则返回underflow(下溢)
Error_code push(const Stack_entry &item);//如果Stack不满,则将元素加到Stack的栈顶,如果Stack是满的,则返回overflow(上溢)
Error_code top(Stack_entry &item)const;//非空的Stack的栈顶元素被复制到item。如果Stack空,返回underflow(下溢)
private:
int count;//数组下标
Stack_entry entry[maxstack];//顺序表
};
Stack::Stack()
{
count = 0;
}
Error_code Stack::push(const Stack_entry &item)
{
Error_code outcome = sucess;
if (count >= maxstack)
outcome = overflow;
else
entry[count++] = item;
return outcome;
}
Error_code Stack::pop()
{
Error_code outcome = sucess;
if (count == 0)
outcome = underflow;
else
--count;
return outcome;
}
Error_code Sta