欢迎来到天天文库
浏览记录
ID:55565973
大小:26.00 KB
页数:7页
时间:2020-05-18
《抢占优先数度算法和时间片轮转调度算法.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
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<<"错误";}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<<"运行:";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
此文档下载收益归作者所有