1)栈
2015-12-05 17:07
281 查看
#include<iostream> #include<iomanip> using namespace std; enum error{overflow,underflow,success}; const int maxlen=100; class stack { public: stack();//初始化 ~stack();//析构 bool empty() const;//判断空 bool full() const;//判断满 int get_front(int &x)const;//取栈顶元素 error push(const int x);//入栈 error pop();//出栈 private: int count;//统计栈中元素的个数 int data[maxlen];//存储栈中数据 }; /* *初始化栈 */ stack:: stack() { count=0; } /* *判断为空 */ bool stack::empty() const{ if(count==0)return true; return false; } /* *判断为满 */ bool stack::full() const{ if(count==maxlen)return true; return false; } /* *取栈顶元素 */ int stack::get_front(int &x)const{ if(empty())return underflow; x=data[count-1]; return success; } /* *入栈 */ error stack::push(const int x){ if(full())return overflow; data[count]=x; count++; return success; } /* *出栈 */ error stack::pop(){ if(empty())return underflow; count--; return success; } stack::~stack() { while(!empty())pop(); } /* *十进制数转化为八进制数 */ int xchg(int n,stack s){ cout<<"十进制:["<<n<<"]->8进制:"; int mod,x; while(n!=0){ mod = n % 8; s.push(mod); n/=8; } while(s.empty()!=true){ s.get_front(x); cout<<x; s.pop(); } cout<<endl; return 0; } int main() { stack s; xchg(100,s); return 0; }
相关文章推荐
- (转)Couchbase介绍,更好的Cache系统
- 6、ZigZag Conversion
- 151205http调试工具Charles Proxy用法详解
- xutils 图片缓存-读取缓存数据
- Google_FaceDetetor CameraHal 实现
- 在Fedora 22下安装配置RealVNC Server 5.2.3的经验总结
- 动态路由各配置格式总结(ripV2、ospf、eigrp、bgp、IS-IS)
- (Android)五分钟让你轻松学会下拉刷新和上拉加载更多
- 两个栈实现队列
- TS科普23 ES PES TS关系
- android okhttp封装使用
- 操作系统习题与答案
- Linux_shell_ grep && awk && sed
- JS按钮控制内容左右滚动
- Timus Online Judge 1577 E-mail(字符串DP)
- jQuery插件开发模式
- EXTJS表格编辑控件验证
- fourcc的涵义以及在C++编程中的实现
- mysql 主从配置
- 高中数学必修3 之 算法初步 和 统计