欢迎来到天天文库
浏览记录
ID:38414502
大小:18.95 KB
页数:7页
时间:2019-06-12
《优先队列(数组 deque)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、数组Pqueue.h#ifndefPQUEUE_H#definePQUEUE_H#includeusingnamespacestd;constintsize=30;typedefstructDataT{intnum;intpri;}DataT;classPqueue{DataTdata[size];intcount;public:Pqueue(){count=0;}boolempty();boolfull();voidinsert(intxnum,intxpri);voidDeleMax();voidprint();};boolPqueue::empty
2、(){if(count==0){returntrue;cout<<"没有数据";}else{returnfalse;}}boolPqueue::full(){if(count==size){returntrue;cout<<"空间已满";}else{returnfalse;}}voidPqueue::insert(intxnum,intxpri){if(!full()){DataTx;x.num=xnum;x.pri=xpri;if(count==0){data[0]=x;count++;}else{for(inti=0;i3、ii;j--){data[j]=data[j-1];}data[i]=x;count++;return;}elseif(i==count-1){data[count]=x;count++;}}}}}voidPqueue::print(){cout<<"队列优先级顺序是"<4、a[i]=data[i+1];}count--;}}#endifPqueue.cpp//Pqueue.cpp:Definestheentrypointfortheconsoleapplication.//#include"stdafx.h"int_tmain(intargc,_TCHAR*argv[]){return0;}#include#include"Pqueue.h"usingnamespacestd;voidmain(){Pqueue*test;test=newPqueue;inta,b,menu;cout<<"1:插入数据2:弹出最大优先值3:5、按优先顺序显示队列4:结束"<>menu;switch(menu){case1:cout<<"输入优先级数据"<>a>>b;test->insert(b,a);break;case2:test->DeleMax();break;case3:test->print();break;case4:return;break;}}}DequeDPqueue.h#ifndefDPQUEUE_H#defineDPQUEUE_H#include#includeusingnamespacestd;ty6、pedefstructDataT{intnum;intpri;//zxkk}DataT;classDPqueue{dequedata;intcount;deque::iteratoriter;public:DPqueue(){count=0;}boolempty();voidinsert(intxnum,intxpri);voidDeleMax();voidprint();};boolDPqueue::empty(){if(data.empty()){returntrue;}else{returnfalse;}}voidDPqueue::inse7、rt(intxnum,intxpri){DataTx;x.num=xnum;x.pri=xpri;if(count==0){data.push_front(x);count++;}else{for(iter=data.begin();iter!=data.end();iter++){if(iter->pri
3、ii;j--){data[j]=data[j-1];}data[i]=x;count++;return;}elseif(i==count-1){data[count]=x;count++;}}}}}voidPqueue::print(){cout<<"队列优先级顺序是"<4、a[i]=data[i+1];}count--;}}#endifPqueue.cpp//Pqueue.cpp:Definestheentrypointfortheconsoleapplication.//#include"stdafx.h"int_tmain(intargc,_TCHAR*argv[]){return0;}#include#include"Pqueue.h"usingnamespacestd;voidmain(){Pqueue*test;test=newPqueue;inta,b,menu;cout<<"1:插入数据2:弹出最大优先值3:5、按优先顺序显示队列4:结束"<>menu;switch(menu){case1:cout<<"输入优先级数据"<>a>>b;test->insert(b,a);break;case2:test->DeleMax();break;case3:test->print();break;case4:return;break;}}}DequeDPqueue.h#ifndefDPQUEUE_H#defineDPQUEUE_H#include#includeusingnamespacestd;ty6、pedefstructDataT{intnum;intpri;//zxkk}DataT;classDPqueue{dequedata;intcount;deque::iteratoriter;public:DPqueue(){count=0;}boolempty();voidinsert(intxnum,intxpri);voidDeleMax();voidprint();};boolDPqueue::empty(){if(data.empty()){returntrue;}else{returnfalse;}}voidDPqueue::inse7、rt(intxnum,intxpri){DataTx;x.num=xnum;x.pri=xpri;if(count==0){data.push_front(x);count++;}else{for(iter=data.begin();iter!=data.end();iter++){if(iter->pri
4、a[i]=data[i+1];}count--;}}#endifPqueue.cpp//Pqueue.cpp:Definestheentrypointfortheconsoleapplication.//#include"stdafx.h"int_tmain(intargc,_TCHAR*argv[]){return0;}#include#include"Pqueue.h"usingnamespacestd;voidmain(){Pqueue*test;test=newPqueue;inta,b,menu;cout<<"1:插入数据2:弹出最大优先值3:
5、按优先顺序显示队列4:结束"<>menu;switch(menu){case1:cout<<"输入优先级数据"<>a>>b;test->insert(b,a);break;case2:test->DeleMax();break;case3:test->print();break;case4:return;break;}}}DequeDPqueue.h#ifndefDPQUEUE_H#defineDPQUEUE_H#include#includeusingnamespacestd;ty
6、pedefstructDataT{intnum;intpri;//zxkk}DataT;classDPqueue{dequedata;intcount;deque::iteratoriter;public:DPqueue(){count=0;}boolempty();voidinsert(intxnum,intxpri);voidDeleMax();voidprint();};boolDPqueue::empty(){if(data.empty()){returntrue;}else{returnfalse;}}voidDPqueue::inse
7、rt(intxnum,intxpri){DataTx;x.num=xnum;x.pri=xpri;if(count==0){data.push_front(x);count++;}else{for(iter=data.begin();iter!=data.end();iter++){if(iter->pri
此文档下载收益归作者所有