您好,欢迎访问三七文档
当前位置:首页 > IT计算机/网络 > C/C++资料 > 按优先数调度算法实现处理机调度-C++程序代码
#includeiostreamusingnamespacestd;structPCB{charName;//进程名floatTime;//要求运行时间intLevel;//优先数boolstate;//状态,1表就绪PCB*next;//指针};voidInit(PCB*head){intnum;PCB*s,*p;cout请输入进程数;cinnum;for(inti=0;inum;i++){p=head;s=newPCB;cout请依次输入进程名要求运行时间优先数;cins-Names-Times-Level;if(s-Time0){s-state=1;while(p-next){if(s-Levelp-next-Level)break;p=p-next;}s-next=p-next;p-next=s;}else{s-state=0;cout此进程要求运行时间时间不符合要求,不添加入进程列表;}}}intRun(PCB*head){PCB*cur,*p;p=head;cur=p-next;p-next=cur-next;cur-Level--;cur-Time--;cout此次执行的进程信息(执行后):进程名;coutcur-Name剩余时间cur-Time优先数cur-Level;if(cur-Time=0){cout状态为完成态endl;deletecur;}else{cout状态为就绪态endl;while(p-next){if(cur-Levelp-next-Level)break;p=p-next;}cur-next=p-next;p-next=cur;}cout此次执行后的进程列表序列为:;p=head;while(p-next){coutp-next-Name;p=p-next;}coutendl;return0;}intmain(){PCB*Head;Head=newPCB;Head-next=NULL;Init(Head);while(Head-next){Run(Head);}return0;}
本文标题:按优先数调度算法实现处理机调度-C++程序代码
链接地址:https://www.777doc.com/doc-5516915 .html