




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quá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/鏈式堆棧的節(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)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年陜西省西安市交通大附屬中學八年級英語第二學期期中監(jiān)測試題含答案
- 2025年建筑施工安全管理信息化對施工現(xiàn)場安全管理的企業(yè)戰(zhàn)略目標優(yōu)化策略優(yōu)化報告
- 2025年工業(yè)互聯(lián)網(wǎng)平臺網(wǎng)絡流量整形技術(shù)在工業(yè)互聯(lián)網(wǎng)平臺產(chǎn)業(yè)融合中的應用報告001
- 2025年醫(yī)藥企業(yè)研發(fā)外包(CRO)模式創(chuàng)新與實踐案例深度解析報告
- 風電光伏培訓課件
- 北京初中化學題庫及答案
- 保險師考試試題及答案
- 安全救護知識試題及答案
- 2025年金融數(shù)據(jù)治理與資產(chǎn)化:金融行業(yè)數(shù)據(jù)共享平臺建設報告
- 醫(yī)院重點科室培訓課件
- 《吸入性肺炎的護理》課件
- 2024-2030年中國卷煙行業(yè)市場未來發(fā)展狀況及投資規(guī)劃研究報告
- 水利水電工程施工企業(yè)“三類人員”安全生產(chǎn)考核題庫-(單選多選題庫)
- 2025《國家安全教育》教學大綱
- 帆狀胎盤的臨床護理
- 外研版(2024)七年級英語上冊++課文中文翻譯
- 【MOOC】結(jié)構(gòu)力學基礎-西南交通大學 中國大學慕課MOOC答案
- 2024廣東省勞動合同范本范本下載
- 水利信息化水質(zhì)監(jiān)測系統(tǒng)單元工程質(zhì)量驗收評定表、檢查記錄
- 心胸外科管理制度
- 客戶月結(jié)協(xié)議合同模板
評論
0/150
提交評論