資源描述:
《搶占優(yōu)先數(shù)度算法和時(shí)間片輪轉(zhuǎn)調(diào)度算法.doc》由會(huì)員上傳分享,免費(fèi)在線(xiàn)閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫(kù)。
1、#include#include#include#includeusingnamespacestd;classpcb{public:charname;intprioORround;intcputime;intcount;intneedtime;charstate;pcb*next;};classcreatepcb{public:pcb*newpcb(intcount){pcb*apcb=newpcb;switch(count){case1:apcb->name='a';break;cas
2、e2:apcb->name='b';break;case3:apcb->name='c';break;case4:apcb->name='d';break;case5:apcb->name='e';break;default:cout<<"錯(cuò)誤";}apcb->prioORround=45+rand()%5;apcb->cputime=0;apcb->count=0;apcb->needtime=10+rand()%5;apcb->state='R';apcb->next=NULL;returnapcb;}private:pcb*p;};classprint{p
3、ublic:voidprintf(pcb*ready,pcb*tail,pcb*finish,pcb*run){p=run;cout<<"運(yùn)行:";while(p->next!=NULL){p=p->next;cout<name<<":"<needtime<<"t";}p=ready;cout<<"就緒:";while(p->next!=tail){p=p->next;cout<name<<":"<needtime<<"t";}p=finish;cout<<"完成:";while(p->next!=NULL){p=p->nex
4、t;cout<name<<":"<needtime<<"t";}cout<count);ready->count+=1;p=ready;while(p->next!=tail&&p->next->prioORround>k->prioORround)p=p->next;k->next=p->next;p->next=k;}voidinsert(pcb*ready
5、,pcb*tail,pcb*finish,pcb*run){pt.printf(ready,tail,finish,run);k=run->next;k->prioORround-=3;k->cputime+=1;k->needtime-=1;k->state='R';k->next=NULL;run->next=NULL;if(k->needtime>0){p=ready;while(p->next!=tail&&p->next->prioORround>k->prioORround)p=p->next;k->next=p->next;p->next=k;}e
6、lse{p=finish;while(p->next!=NULL)p=p->next;p->next=k;}}private:pcb*p;pcb*k;createpcbct;printpt;};classinsert2{public:voidinsert(pcb*ready,pcb*tail){k=ct.newpcb(ready->count);ready->count+=1;p=ready;while(p->next!=tail)p=p->next;k->next=p->next;p->next=k;}voidinsert(pcb*ready,pcb*tail
7、,pcb*finish,pcb*run){pt.printf(ready,tail,finish,run);k=run->next;k->cputime+=2;k->needtime-=2;k->state='R';k->next=NULL;run->next=NULL;if(k->needtime>0){p=ready;while(p->next!=tail)p=p->next;k->next=p->next;p->next=k;}else{p=finish;while(p->next!=NULL)p=p->next;p->next=k;}}private:p
8、cb*p;pcb*k;c