版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、#include<iostream>#include <process.h>const bool TURE=1;const bool FAULT=0;using std:cout;using std:cin;using std:endl;class Node/链式堆栈的节点类public:Node();/构造函数重载1Node(int , int , int ,Node *);/构造函数重载2void const get_data(int &, int &,int &);/取节点数据 void put_data(int , int ,int );
2、/置节点数据bool put_next(Node *);/置节点的前驱节点域 bool put_prior(Node *);/置结点的后继结点域Node* const get_next()const;/取结点的前驱结点域 Node* const get_prior()const;/取结点的后继结点域 private:Node *next;Node *prior;int minute;int second;int num;Node:Node()minute=NULL;second=NULL;num=0;next=NULL;prior=NULL;Node:Node(int x, int y, in
3、t z ,Node *p)minute=x;second=y;num=z;next=NULL;prior=p;void const Node:get_data(int &x, int &y, int &z) x=minute;y=second;z=num;void Node:put_data(int x, int y, int z) minute=x;second=y;num=z;bool Node:put_next(Node *n)next=n;return TURE;bool Node:put_prior(Node *p)prior=p;return TURE;No
4、de* const Node:get_next() const return next;Node* const Node:get_prior() const return prior;class Queuepublic:Queue();/堆栈类的构造函数int get_length(void);/取堆栈的长度 bool push(int , int , int );/数据压栈bool pop(int &, int & , int &);/数据出栈 void print(void);int const seach(int );/搜索堆栈数据 protected:Node
5、base;/根节点Node *top;/顶节点int length;Queue:Queue():base()/构造函数,数据初始化 length=0;top=&base;int Queue:get_length(void)/取长度if(length<0) length=0;return length;bool Queue:push(int minute, int second, int num)/数据压栈 if(top!=NULL)length+;Node *temp=new Node(minute,second,num,top); top->put_next(temp);
6、top=temp;elsereturn FAULT;return TURE;bool Queue:pop(int &minute, int &second, int &num) if(base.get_next()!=NULL)length-;Node *temp=base.get_next();temp->get_data(minute,second,num);if(temp->get_next()!=NULL)Node *temp1=temp->get_next();temp1->put_prior(&base);base.put_n
7、ext(temp1);elsetop=&base;base.put_next(NULL);delete temp;elsereturn FAULT;return TURE;int const Queue:seach(int num)/搜索堆栈数据Node *temp;int x,y,z;temp=&base;while(temp!=NULL)temp->get_data(x,y,z);if(x=num) return 1;temp=temp->get_next();return 0;void Queue:print()/打印堆栈Node *temp;int x,y,
8、z,n=1;temp=base.get_next();if(temp=NULL)cout<<"数据为空"<<endl;while(temp!=NULL)temp->get_data(x,y,z);if(y=1)cout<<n<<": 第"<<x<<"号人士 性别:男 跳舞次数:"<<z<<endl; elsecout<<n<<": 第"<<x<<"号人士 性
9、别:女 跳舞次数:"<<z<<endl; temp=temp->get_next();n+;void ring_over(Queue &, Queue &, Queue &, Queue &);main()int sex,n=0,man_num=0,woman_num=0,number=0,degree5050=0,time=0,lun; Queue man,buffer_man,woman,buffer_woman;dosystem("cls");docout<<"请输入&quo
10、t;<<n+1<<"号人物性别(1:男士2:女士0:输入完毕)(总数不得超过100)"<<endl;cin>>sex;while(sex<0|sex>2);if(sex=1)man.push(n+1,sex,NULL);man_num+;n+;if(sex=2)woman.push(n+1,sex,NULL);woman_num+;n+;if(sex=0)system("cls");cout<<"输入结束,共有"<<woman_num+man_num&
11、lt;<"名人士参与舞会"<<endl; cout<<"打印男士信息"<<endl;man.print();cout<<"打印女士信息"<<endl;woman.print();system("pause");break;while(sex>=0&&sex<=2);system("cls");docout<<"请输入舞会轮数:"<<endl;cin>&g
12、t;lun;while(lun<0);while(time<lun)for(;)if(woman.get_length()=0)ring_over(man,woman,buffer_man,buffer_woman); time+;break;else if(man.pop(man_num,sex,number)=0) ring_over(man,woman,buffer_man,buffer_woman); time+;break;elsebuffer_man.push(man_num,sex,number+1); if(woman.pop(woman_num,sex,numbe
13、r)buffer_woman.push(woman_num,sex,number+1); elsering_over(man,woman,buffer_man,buffer_woman); time+;break;degreeman_numwoman_num+;system("cls");cout<<"第"<<lun<<"舞会结束"<<endl;ring_over(man,woman,buffer_man,buffer_woman); cout<<"打印每人的跳舞总
14、数:"<<endl;cout<<"打印男士信息"<<endl;man.print();cout<<"打印女士信息"<<endl;woman.print();docout<<"请输入甲得号码"<<endl;cin>>man_num;while(man.seach(man_num)=0);docout<<"请输入乙得号码"<<endl;cin>>woman_num;while(woman.seach(woman_num)=0);cout<<"第"<<man_num<<"号男士"<<"和第"<<woman_num<<"号女士共跳了"<<degreeman_numwoman_num<<"次舞"<<endl;return 0;
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年河北邯郸市文化广电和旅游局为市平调落子剧团公开选聘戏曲演员及演奏员16名参考题库附答案详解(培优a卷)
- 2025广东中共中山市委宣传部所属事业单位招聘事业单位人员14人参考题库及答案详解(名师系列)
- 2025广东中共中山市委宣传部所属事业单位招聘事业单位人员14人参考题库附答案详解(b卷)
- 2025广东河源市紫金县上义镇人民政府招聘编外人员1人参考题库带答案详解
- 2025广东深圳市光明区人民政府办公室招聘(选聘)专干4人参考题库附答案详解(基础题)
- 2025广西崇左凭祥市应急管理局编外工作人员招聘1人参考题库含答案详解(巩固)
- 2025广西师范大学劳动合同制员工招聘1人参考题库及答案详解1套
- 2025年龙门石窟研究院引进硕士研究生15名参考题库附答案详解(综合题)
- 2025年农业行业数字农业与智能农业研究报告及未来发展趋势
- 2025年网络安全行业网络安全技术应用与风险防范研究报告及未来发展趋势预测
- 2025国网能源研究院限公司高校毕业生招聘【21人】事业单位易考易错模拟试题(共500题)试卷后附参考答案
- 白血病患者日常护理建议
- 2025年及未来5年中国鱼具行业市场运营现状及投资战略咨询报告
- 《政务信息系统运行维护费用定额测算方法》
- 【课件】消防月:消防安全知识培训
- 2025健身房与瑜伽馆合作经营合同
- 户外灯光架施工方案
- 2025年农产品食品质量安全检验员技能及理论知识考试题库附含答案
- 四川省公务员2025年考试行测言语理解真题试卷(含答案)
- 矿山绿色矿业建设规划
- 电玩赛车活动方案
评论
0/150
提交评论