栈的实现
来源:互联网 发布:怎么在origin显示数据 编辑:程序博客网 时间:2024/05/20 23:07
const int maxstack=100;
enum Error_code={success,overflow,underflow};
class Stack{
public:
Stack();
bool empty()const; // 常函数,only read
Error_code pop();
Error_code top(Stack_entry&item)const;
Error_code push(const Stack_entry&item);
private:
int count;
Stack_entry entry[maxstack];
};
//入栈
Error_code Stack ::push(const Stack_entry&item)
{
Error_code outcome=success;
if(count>=maxstack)
outcome=overflow;
else
entry[count++]=item;
return outcome;
}
//出栈
Error_code Stack::pop()
{
Error_code outcome=success;
if(count==0)
outcome=underflow;
else
--count;
return outcome;
}
//访问栈顶元素
Error_code Stack::top(Stack_entry&item)const
{
Error_code outcome=success;
if(count==0)
outcome=underflow;
else
item=entry[count-1];
return outcome;
}
bool Stack::empty()const
{
bool outcome=true;
if(count>0)outcome=false;
return outcome;
}
//栈的初始化
Stack::Stack()
{
count=0;
}
- 栈的顺序实现
- 栈的数组实现
- 栈的指针实现
- 栈的实现
- 栈的实现
- 顺序栈的实现
- 栈的实现
- 链栈的实现
- 栈的C++实现
- 栈的实现
- 栈的宏实现
- 栈的实现
- 顺序栈的实现
- 链栈的实现
- 栈的链式实现
- 链式栈的实现
- 用链表实现的栈
- 栈的简单实现
- 堆与堆排序
- 一个好用的js分页
- Java学习笔记之 类与对象1
- 内存泄漏常见情况及解决方法
- Open vSwitch 使用
- 栈的实现
- JSONObject简介
- C语言中常用的关键字
- 远程调用对比RMI、MINA、ESB、Burlap、Hessian、SOAP、EJB和JMS
- 常用stl 容器用法
- Struts2的数据校验
- sql别名何时使用
- MySQL数据库备份命令
- localtime_r在多线程环境下可能存在死锁