




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
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é)點(diǎn)類(lèi)public:Node();/構(gòu)造函數(shù)重載1Node(int , int , int ,Node *);/構(gòu)造函數(shù)重載2void const get_data(int &, int &,int &);/取節(jié)點(diǎn)數(shù)據(jù) void put_data(int , int ,int );
2、/置節(jié)點(diǎn)數(shù)據(jù)bool put_next(Node *);/置節(jié)點(diǎn)的前驅(qū)節(jié)點(diǎn)域 bool put_prior(Node *);/置結(jié)點(diǎn)的后繼結(jié)點(diǎn)域Node* const get_next()const;/取結(jié)點(diǎn)的前驅(qū)結(jié)點(diǎn)域 Node* const get_prior()const;/取結(jié)點(diǎn)的后繼結(jié)點(diǎn)域 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();/堆棧類(lèi)的構(gòu)造函數(shù)int get_length(void);/取堆棧的長(zhǎng)度 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é)點(diǎn)Node *top;/頂節(jié)點(diǎn)int length;Queue:Queue():base()/構(gòu)造函數(shù),數(shù)據(jù)初始化 length=0;top=&base;int Queue:get_length(void)/取長(zhǎng)度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<<"號(hào)人士 性別:男 跳舞次數(shù):"<<z<<endl; elsecout<<n<<": 第"<<x<<"號(hào)人士 性
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<<"請(qǐng)輸入&quo
10、t;<<n+1<<"號(hào)人物性別(1:男士2:女士0:輸入完畢)(總數(shù)不得超過(guò)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;<"名人士參與舞會(huì)"<<endl; cout<<"打印男士信息"<<endl;man.print();cout<<"打印女士信息"<<endl;woman.print();system("pause");break;while(sex>=0&&sex<=2);system("cls");docout<<"請(qǐng)輸入舞會(huì)輪數(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<<"舞會(huì)結(jié)束"<<endl;ring_over(man,woman,buffer_man,buffer_woman); cout<<"打印每人的跳舞總
14、數(shù):"<<endl;cout<<"打印男士信息"<<endl;man.print();cout<<"打印女士信息"<<endl;woman.print();docout<<"請(qǐng)輸入甲得號(hào)碼"<<endl;cin>>man_num;while(man.seach(man_num)=0);docout<<"請(qǐng)輸入乙得號(hào)碼"<<endl;cin>>woman_num;while(woman.seach(woman_num)=0);cout<<"第"<<man_num<<"號(hào)男士"<<"和第"<<woman_num<<"號(hào)女士共跳了"<<degreeman_numwoman_num<<"次舞"<<endl;return 0;
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025至2030中國(guó)自由流澆注機(jī)蓋行業(yè)產(chǎn)業(yè)運(yùn)行態(tài)勢(shì)及投資規(guī)劃深度研究報(bào)告
- 2025至2030中國(guó)自助服務(wù)亭行業(yè)市場(chǎng)深度研究及發(fā)展前景投資可行性分析報(bào)告
- 2025至2030中國(guó)自動(dòng)多畫(huà)面展示機(jī)行業(yè)市場(chǎng)占有率及投資前景評(píng)估規(guī)劃報(bào)告
- 超微定位技術(shù)在物聯(lián)網(wǎng)領(lǐng)域的應(yīng)用案例研究
- 2025至2030中國(guó)腋下拐杖行業(yè)市場(chǎng)深度研究及發(fā)展前景投資可行性分析報(bào)告
- 2025至2030中國(guó)腦脊髓液管理裝置行業(yè)產(chǎn)業(yè)運(yùn)行態(tài)勢(shì)及投資規(guī)劃深度研究報(bào)告
- 2025至2030中國(guó)胸骨閉合器行業(yè)產(chǎn)業(yè)運(yùn)行態(tài)勢(shì)及投資規(guī)劃深度研究報(bào)告
- 2025至2030中國(guó)肛瘺非手術(shù)治療行業(yè)產(chǎn)業(yè)運(yùn)行態(tài)勢(shì)及投資規(guī)劃深度研究報(bào)告
- 企業(yè)日常運(yùn)營(yíng)中的信息安全與保密管理技巧分享
- 2025至2030中國(guó)網(wǎng)絡(luò)通信設(shè)備行業(yè)發(fā)展趨勢(shì)與發(fā)展趨勢(shì)分析與未來(lái)投資戰(zhàn)略咨詢研究報(bào)告
- 石油化工監(jiān)理工作報(bào)告
- 2025-2030中國(guó)餐廚垃圾處理服務(wù)行業(yè)市場(chǎng)現(xiàn)狀分析及競(jìng)爭(zhēng)格局與投資發(fā)展研究報(bào)告
- 2025年反假幣知識(shí)競(jìng)賽題庫(kù)及答案(共50題)
- 智能制造中的信息安全保障
- 水利工程隱患排查清單
- 酒店評(píng)優(yōu)方案
- 企業(yè)戰(zhàn)略管理試題及答案 12套試卷
- 法瑞西單抗注射液-藥品臨床應(yīng)用解讀
- 食堂原材料采購(gòu)管理方案及食品保存管理方案
- 2025年高級(jí)考評(píng)員職業(yè)技能等級(jí)認(rèn)定考試題(附答案)
- 滄州市鹽山縣2024-2025學(xué)年五年級(jí)數(shù)學(xué)第二學(xué)期期末復(fù)習(xí)檢測(cè)試題含答案
評(píng)論
0/150
提交評(píng)論