




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、#iiiclude#iiiclude const bool TURE=1;const bool FAULT=0;using std:cout;using std:cm;using std:endl;class Node链式堆栈的节点类public:Node。;/构造函数重载1Node(int, int, int .Node *);/构造函数重载 2void const get_data(iiit &, mt &,int &)/取节点数据 void put_data(iiit, int ,iiit);置节点数据 bool put_next(Node *);/置节点的前驱节点域 bool put_
2、pnoi(Node *);置结点的后继结点域 Node* const gecnext()coiist/取结点的前驱结点域 Node * const get_pnor()const;取结点的后继结点域 private:Node *next;Node *pnor;mt niniute;mt second;mt num;Node:Node()niiiiute=NULL;second=NULL;num=0;next=NULL;pnor=NULL;Node:Node(iiit x, int y, int z .Node *p)niiiiute=x;second=v;num=z;next=NULL;pno
3、r=p;void const Node:get_data(int &x, int &y, hit &z)x=niuiute;y=second;z=num;void Node: :put_data(iiit x, int y, int z)niiiiute=x;secondly;num=z;bool Node: :put_next(Node *n)next=n;return TURE;bool Node:put_prior(Node *p)pnor=p;return TURE;Node* const Node:geCnextQ constreturn next;Node* const Node:
4、get_piiorQ constreturn prior;class Queue(public:Queue();堆栈类的构造函数mt get_length(void);/ 取堆栈的长度bool push(int, int. mt);/数据压栈bool pop(int &, mt & , mt &);数据出栈 void print(void);mt const seach(int);搜索堆栈数据 protected:Node base;/根节点Node *top;/顶节点 mt lengtli;Queue: :Queue():base()/构造函数,数据初始化length=0;top=&base
5、;hit Queue:get_length(void)/取长度if(lengthput_next(temp);top=tenip;)else(return FAULT;)return TURE;bool Queue:pop(int &nimute, mt &second, mt &num)if(base. get_next()! =NULL)(length-;Node *temp=base.get_next();temp-geCdata(nmiute.second,num);if(temp-get_next() !=NULL)(Node *temp 1 =temp-get_next();tem
6、p 1 -put_piior(&base);base.put_next(templ);)else(top=&base;base.put_next(NULL);)delete temp:elsereturn FAULT;)return TURE;mt const Queue: :seach(int num)/IS索堆栈数据Node *temp;int x,y,z;temp=&base;wliile(temp !=NULL)(temp-get_data(x,y,z);if(x=num) leturn 1;temp=tenip-get_nextQ;return 0;void Queue:piint(
7、)/打印堆栈Node *temp;mt x,y,z,n=l;temp=base. get_nextQ;if(temp=NULL)coutH 数据为空 ”v vendl;wliile(temp !=NULL)(temp-get_data(x,y,z);if(y=l)coutnH:第,xM号人士 性别:男 跳舞次数:”vvzvvendl; elsecoutn:第vvxvv”号人士 性别:女 跳舞次数:zend; temp=tenip-get_nextQ; n+;)void ring_over(Queue &. Queue & Queue & Queue &);main()int sex,ii=0.
8、maii_num=0,woman_num=0,iiumber=0,degree5050=0,time=0,hm;Queue man.bufifei_man,woman,buffer_wonian;dosysteni(Mclsn);do(cout请输入”n+ivv“号人物性别(1:男士 2:女士 0:输入完毕)(总数不得超过 100)Hendl;cinsex;while(sex2);if(sex=l)(nian.push(n+1,sex,NULL);nian_num+;n+;)iRsex=2)(woman.push(n+1 ,sex,NULL);woman_num+4-;n+;if(sex=0)
9、(system(MclsH);coutn输入结束,共有”vvwoman_mim+nian_mim=0&sex=2);system(HclsM);do(cout请输入舞会轮数:“vvendl;cinlun;while(lun0);while(timelun) for(;)if(woman.geclength()=0) nng_over(maii,woinan,buffer_nian,buffer_woman);time+;break;else if(nian.pop(nian_num,sex,numbei)=0)(nng_over(maii,woinan,buffer_nian,buffer_w
10、oman);time+;break;else(buflfei_nian.push(man_nunLsex.number+1);)if(woman.pop(woman_num,sex,numbei)bufifei_wonian.push(woman_num,sex,numbei+l);else(nng_over(maii,woinan,buffer_nian,buffer_woman);time+;break;degree nian_num woman_num+;system(Hclsn);coutH 第“vvhmvv” 舞会结束 Hendl;iiiig_ovei(man,woman.buflf
11、er_man,buffer_wonian);cout打印每人的跳舞总数:,*endl;cout打印男士信息endl;maii.pnntQ;cout打印女士信息endl;woman, print。;do(cout,f请输入甲得号码”endl;cinnian_num; while(man. seach(nian_num)=O);do(coutM请输入乙得号码Hendl;c inwoman_num;while(wonian. seach(woinan_num)=0);coutM 第,nian-numH 号男 士 HH 和第 ”vvwoman_iiumvv” 号女士 共跳了 Mdegreemaivnum woman_numM 次舞 Hendl;return 0;void ring_over(Queue &man. Queue &woman.
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 工程轮胎改造合同协议
- 工程项目付款合同协议
- 工程装修维修合同协议
- 上下游经销合同协议
- epc项目商务合同协议
- 建设蔬菜大棚合同协议
- 三方解除协议合同协议
- 5方合作协议合同协议
- 合同采购转让协议范本
- 工程机械租合同协议
- 期中(试题)-2024-2025学年人教精通版(2024)英语三年级下册
- 2025-2030中国煤焦油杂酚油行业市场发展趋势与前景展望战略研究报告
- 防洪防汛安全教育知识培训
- 2020-2025年中国辽宁省风力发电行业发展潜力分析及投资方向研究报告
- 规模养殖场十项管理制度
- 2025航天知识竞赛考试题库(含答案)
- 2025中考英语热点话题阅读《哪吒2魔童闹海》
- 劳务派遣劳务外包项目方案投标文件(技术方案)
- 疟疾2025培训课件
- 流行性感冒诊疗方案(2025版)解读课件
- 2025年度打印机销售与升级改造合同模板4篇
评论
0/150
提交评论