資源描述:
《搶占優(yōu)先數(shù)調度算法和時間片輪轉調度算法》由會員上傳分享,免費在線閱讀,更多相關內容在行業(yè)資料-天天文庫。
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;case2:apcb->nam
2、e='b';break;case3:apcb->name='c';break;case4:apcb->name='d';break;case5:apcb->name='e';break;default:cout<<"錯誤";}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{public:voidprintf(pcb*rea
3、dy,pcb*tail,pcb*finish,pcb*run){p=run;cout<<"運行:";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->next;cout<name<<":"<needtime<<"
4、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,pcb*tail,pcb*finish,pcb*run){pt.printf(ready,ta
5、il,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;}else{p=finish;while(p->next!=NULL)p=p->next;p->next=k;}}priva
6、te: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,pcb*finish,pcb*run){pt.printf(ready,tail,finish,run);k=run->next;k->cpu
7、time+=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:pcb*p;pcb*k;c