使用1維數(shù)組實現(xiàn)“優(yōu)先級隊列”,實現(xiàn)好該類后,自己編寫主程序驗證該類各方法正確性。struct?Queue_entry?{??data_entry?data;???int?priority;};?const?int?maxqueue?=?50;?//??small?value?for?testingclass?PriorityQueue?{public:???PriorityQueue();???bool?empty()?const;???Error_code?serve();???Error_code?append(const?Queue_entry?&item);???Error_code?retrieve(Queue_entry?&item)?const;protected:???int??rear;?????????????//??front?stays?at?0???Queue_entry?entry[maxqueue];};?PriorityQueue::?PriorityQueue()/*?Post:?The?PriorityQueue?is?initialized?to?be?empty.?*/{??}?bool?PriorityQueue::empty()?const/*?Post:?Return?true?if?the?PriorityQueue?is?empty,?otherwise?return?false.?*/{??}?Error_code?PriorityQueue::serve()/*?Post:?The?front?of?the?PriorityQueue?is?removed.?If?the?PriorityQueue?is?empty?return?an?Error_code?of?underflow.?*/{??}?Error_code?PriorityQueue::retrieve(Queue_entry?&item)?const/*??Post:?The?front?of?the?PriorityQueue?retrieved?to?the?output?parameter?item.?If?the?PriorityQueue?is?empty?return?an?Error_code?of?underflow.??*/{??}?Error_code?PriorityQueue::append(const?Queue_entry?&item)/*??Post:?item?is?added?to?the?rear?of?the?PriorityQueue?and?adjust?to?the?proper?position?by?priority?field.?If?the?PriorityQueue?is?full?return?an?Error_code?of?overflow.*/{??}注意:0號下標為隊首元素;優(yōu)先級priority的數(shù)值越大表明越應放在靠近隊首的地方;優(yōu)先級最高的為隊首元素。實現(xiàn)提示:插入一個元素時,先放在隊尾,之后根據(jù)其優(yōu)先級把它按照類似排序的方法向前移到合適的位置(其后元素優(yōu)先級小于該元素優(yōu)先級;其前元素優(yōu)先級大于或等于該元素優(yōu)先級)。因此,隊列中元素實際上是按照優(yōu)先級遞減的。刪除一個元素時,出隊的元素是隊列首元(優(yōu)先級最高的元素)。數(shù)據(jù)結構2017級大作業(yè)01_測試用例-------------------------------------------=========================================注意:此次檢測的例子中,數(shù)據(jù)為字符:char=================================================PART?1========typedef?char?data_entry;========PART?2========int?main(){????cout?<<?"Priority?Queue!"?<<?endl;????PriorityQueue?pq;????Queue_entry?qe[10];????Queue_entry?item;????for(int?i=0;?i<10;?i++)?{????????qe[i].data='A'+i;????????qe[i].priority=1+i;????}????for(int?i=0;?i<5;?i++)?{????????pq.append(qe[i]);????}????while?(pq.empty()==false)?{????????pq.retrieve(item);????????cout<<item.data<<":"<<item.priority<<endl;????????pq.serve();????}????return?0;}??????????????大作業(yè)具體扣分如下Testing?????????□?-2?missing?test?for?the?method?“empty?”□?-2?missing?test?for?the?method?“append”□?-2?missing?test?for?the?method?“serve”□?-2?missing?test?for?the?method?“retrieve”□?-2?missing?test?for?the?constructor?method?The?methods?in?the?Class?“PriorityQueue”:empty?????□?-5?not?implemented/fail?to?explain?the?code???????□?-3?misfunctionappend??□?-10?not?implemented/fail?to?explain?the?code??????□?-5?misfunctionserve??????□?-5?not?implemented/fail?to?explain?the?code???????□?-3?misfunctionretrieve???□?-5?not?implemented/fail?to?explain?the?code????????□?-3?misfunctionPriorityQueue???□?-5?not?implemented/fail?to?explain?the?code???□?-3?misfunction??The?attributes?in?the?Class?“PriorityQueue”:??????????????□?-5??????add?attributes???□?-5??????remove?attributes?Source?Code???10?Marks(6+4)Style:?????????□?-1????missing?your?details??□?-4????insufficient?comments??□?-1????improper?names?Separated?4?Files?(Utility.h;??PriorityQueue.h;??PriorityQueue.cpp;??main.cpp):???□?-3???miss?3?files????□?-2???miss?2?files??????□?-1???miss?1?file?
大課作業(yè),不會寫,請大佬幫忙
1710010101陳沐梓
2019-04-10 15:41:09