




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
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/鏈?zhǔn)蕉褩5墓?jié)點類public:Node();/構(gòu)造函數(shù)重載1Node(int , int , int ,Node *);/構(gòu)造函數(shù)重載2void const get_data(int &, int &,int &);/取節(jié)點數(shù)據(jù) void put_data(int , int ,int );
2、/置節(jié)點數(shù)據(jù)bool put_next(Node *);/置節(jié)點的前驅(qū)節(jié)點域 bool put_prior(Node *);/置結(jié)點的后繼結(jié)點域Node* const get_next()const;/取結(jié)點的前驅(qū)結(jié)點域 Node* const get_prior()const;/取結(jié)點的后繼結(jié)點域 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();/堆棧類的構(gòu)造函數(shù)int get_length(void);/取堆棧的長度 bool push(int , int , int );/數(shù)據(jù)壓棧bool pop(int &, int & , int &);/數(shù)據(jù)出棧 void print(void);int const seach(int );/搜索堆棧數(shù)據(jù) protected:Node
5、base;/根節(jié)點Node *top;/頂節(jié)點int length;Queue:Queue():base()/構(gòu)造函數(shù),數(shù)據(jù)初始化 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)/數(shù)據(jù)壓棧 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)/搜索堆棧數(shù)據(jù)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<<"數(shù)據(jù)為空"<<endl;while(temp!=NULL)temp->get_data(x,y,z);if(y=1)cout<<n<<": 第"<<x<<"號人士 性別:男 跳舞次數(shù):"<<z<<endl; elsecout<<n<<": 第"<<x<<"號人士 性
9、別:女 跳舞次數(shù):"<<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:輸入完畢)(總數(shù)不得超過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<<"輸入結(jié)束,共有"<<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<<"請輸入舞會輪數(shù):"<<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<<"舞會結(jié)束"<<endl;ring_over(man,woman,buffer_man,buffer_woman); cout<<"打印每人的跳舞總
14、數(shù):"<<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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 大思政課視域下跨學(xué)科協(xié)同育人與社會責(zé)任感培養(yǎng)
- 導(dǎo)管室護理工作指南
- 職業(yè)教育教材建設(shè)與管理研究
- 東北財經(jīng)大學(xué)《社會福利實踐技術(shù)》2023-2024學(xué)年第一學(xué)期期末試卷
- 江蘇財經(jīng)職業(yè)技術(shù)學(xué)院《港澳臺文學(xué)專題研究》2023-2024學(xué)年第一學(xué)期期末試卷
- 元旦晚會抽簽課件
- 廣州南方學(xué)院《三筆訓(xùn)練》2023-2024學(xué)年第一學(xué)期期末試卷
- 鹽城工業(yè)職業(yè)技術(shù)學(xué)院《專業(yè)應(yīng)用英語》2023-2024學(xué)年第一學(xué)期期末試卷
- 湖南九嶷職業(yè)技術(shù)學(xué)院《建筑師職業(yè)基礎(chǔ)(含務(wù)實與法規(guī))》2023-2024學(xué)年第一學(xué)期期末試卷
- 2025年巧克力項目規(guī)劃申請報告
- 2025年光伏發(fā)電項目合同能源管理合同
- 2025年河北交通投資集團有限公司招聘筆試參考題庫含答案解析
- 2020-2021學(xué)年河南省鄭州市八下期末數(shù)學(xué)試卷(原卷版)
- 家具公司工藝流程
- 《吸入性肺炎的護理》課件
- 2024-2030年中國卷煙行業(yè)市場未來發(fā)展?fàn)顩r及投資規(guī)劃研究報告
- 水利水電工程施工企業(yè)“三類人員”安全生產(chǎn)考核題庫-(單選多選題庫)
- 2025《國家安全教育》教學(xué)大綱
- 帆狀胎盤的臨床護理
- 【MOOC】結(jié)構(gòu)力學(xué)基礎(chǔ)-西南交通大學(xué) 中國大學(xué)慕課MOOC答案
- 2024廣東省勞動合同范本范本下載
評論
0/150
提交評論