循环队列和杨辉三角(Cyclic queue and Yang Hui triangle).doc

上传人:rrsccc 文档编号:8775747 上传时间:2021-01-15 格式:DOC 页数:10 大小:40.50KB
返回 下载 相关 举报
循环队列和杨辉三角(Cyclic queue and Yang Hui triangle).doc_第1页
第1页 / 共10页
循环队列和杨辉三角(Cyclic queue and Yang Hui triangle).doc_第2页
第2页 / 共10页
循环队列和杨辉三角(Cyclic queue and Yang Hui triangle).doc_第3页
第3页 / 共10页
循环队列和杨辉三角(Cyclic queue and Yang Hui triangle).doc_第4页
第4页 / 共10页
循环队列和杨辉三角(Cyclic queue and Yang Hui triangle).doc_第5页
第5页 / 共10页
点击查看更多>>
资源描述

《循环队列和杨辉三角(Cyclic queue and Yang Hui triangle).doc》由会员分享,可在线阅读,更多相关《循环队列和杨辉三角(Cyclic queue and Yang Hui triangle).doc(10页珍藏版)》请在三一文库上搜索。

1、循环队列和杨辉三角(Cyclic queue and Yang Hui triangle)circulatequeue。H:类circulatequeue私人:int数据;/ /数组在前、后;/ /队头队尾指针,下标int长度;/ /队列长度const int ini_mem_length;/ /动态数组初始大小const int增量;/ /数组扩展增量/ / / /内存利用率const双率;国际current_mem_length;/ /当前数组内存单元大小公共:circulatequeue(int = 100,int = 10);/构造 circulatequeue() /析构删除 数据;

2、输出(void);/ /输出,调试用无效enterqueue(int值);/ /入队列int DeleteQueue(int值);/ /出队列国际getqueuelength(void)/获取当前队列的长度返回的长度;int GetTop(int值)/取队头元素如果(0 =长度)返回- 1;int i =(前+ 1)% current_mem_length;值=数据 i ;返回1;CirculateQueue.cpp:#包括“circulatequeue。”#包含iostream 使用名称空间;circulatequeue:CirculateQueue(int,int newsize,newi

3、ncrement):ini_mem_length(newsize)、增量(newincrement)数据=新国际 ini_mem_length ;长度= 0;前面=后面= 0;current_mem_length = ini_mem_length;无效circulatequeue:输出(void)如果(0 =长度)cout “当前队列为空!“”不当前队列动态数组长度为:“ current_mem_length endl;其他的cout “当前队列长度为:“长“不当前队列动态数组长度为:“ current_mem_length endl;cout “当前队列内容为:”;int pos =(前+

4、1)% current_mem_length;对于(int = i 1;i =长度;i + +)cout 数据【词性】“T”;POS =(POS + 1)% current_mem_length;cout 使用名称空间;#包括“circulatequeue。”虚空(void)/杨辉三角输出Yanghuiint n;做/输入cout “请输入一个大于2的整数:”;CIN;(n3);/ /实际的算法cout “=” N “的杨辉三角输出为:“ endl;为(int1;kn-1;K + +)cout “”;cout 1 endl;对于(k1);k = n - 2; k + +)court ;cour

5、t 1 1 endl;circulatequeue yanghuiqueue;yanghuiqueue.enterqueue (1);yanghuiqueue.enterqueue (2);yanghuiqueue.enterqueue (1);int data1, data2;for (int i = 1; i = n - 3; i + +) / / 输出当前行, 生成下一行的内容yanghuiqueue.enterqueue (1); / / 插入下一行的第一个 1;for (k = 1 and k = n 2 i; k + +)court ;for (int j = 1; j = i +

6、 1, j + +)yanghuiqueue.deletequeue (data1);court data1 ;yanghuiqueue.gettop (data2);yanghuiqueue.enterqueue (data1 + data2);yanghuiqueue.deletequeue (data1);court data1 endl;yanghuiqueue.enterqueue (1); / / 插入下一行的最后一个 1;/ / 输出最后一行;while (0! = yanghuiqueue.getqueuelength ()yanghuiqueue.deletequeue (data1);court data1 ;court endl;void main (void)yanghui ();court endl;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1