2)杨辉三角[1]队列实现
2015-11-13 21:56
429 查看
#include<iostream> #include<iomanip> using namespace std; enum error{overflow,underflow,success}; const int maxlen=100; class queue{ public: queue(); bool empty()const; bool full()const; int get_front(int &x)const; error append(const int x); error serve(); private: int count; int rear,front; int data[maxlen]; }; queue::queue(){ count=0; rear=front=0; } bool queue::empty()const{ if(count==0)return true; return false; } bool queue::full()const{ if(count==maxlen)return true; return false; } int queue::get_front(int &x)const{ if(empty())return underflow; x=data[(front+1)%maxlen]; return success; } error queue::append(const int x){ if(full())return overflow; rear=(rear+1)%maxlen; data[rear]=x; count++; return success; } error queue::serve(){ if(empty())return underflow; front=(front+1)%maxlen; count--; return success; } int main(){ queue q; int n; cin>>n; int s1,s2; for(int i=1;i<n;i++)cout<<" "; cout<<1<<endl; q.append(1); for(int i=2;i<=n;i++){ s1=0; for(int k=1;k<=n-i;k++ )cout<<" "; for(int j=1;j<=i-1;j++){ q.get_front(s2); q.serve(); cout<<s1+s2<<setw(4); q.append(s1+s2); s1=s2; } cout<<1<<endl; q.append(1); } return 0; }
相关文章推荐
- Java学习中遇到的问题01_IO流
- Codeforces 595A Vitaly and Night 【水题】
- MyEclipse强制退出后闪退进不去workbench
- svn的服务器的配置
- 第十六章 综合实例
- 第十七章 OAuth2集成
- Java 声明变量名的规则
- 第十五章 单点登录
- 在64位Ubuntu 14.04 LTS 中安装praat
- 遍历一个文件夹下面的文件(半原创)
- 第十三章 RememberMe
- 第十四章 SSL
- Mingw64编译wxWidgets3.0.2常见错误
- ssh相关操作
- 作业:按钮控制打开关闭新窗口及新窗口按钮关闭父窗口
- LightOJ 1036 - A Refining Company(dp)
- 创建网页版UFT脚本技术点
- 哈密顿算符
- HDU 5493 Queue(线段树)
- Poj.2689 Prime Distance【素数筛选】 2015/11/13