《按优先数调度算法实现处理机调度C++程序代码.doc》由会员分享,可在线阅读,更多相关《按优先数调度算法实现处理机调度C++程序代码.doc(3页珍藏版)》请在金锄头文库上搜索。
1、#includeusing namespace std; struct PCB char Name; /进程名 float Time; /要求运行时间 int Level; /优先数 bool state; /状态,1表就绪 PCB *next; /指针 ; void Init(PCB *head) int num; PCB *s,*p; coutnum; for(int i=0;i num;i+) p=head; s=new PCB; couts-Names-Times-Level; if(s-Time0) s-state =1; while(p-next) if(s-Level p-nex
2、t-Level )break; p=p-next ; s-next=p-next; p-next=s; else s-state =0; coutnext; p-next =cur-next; cur-Level-; cur-Time-; cout此次执行的进程信息(执行后):进程名; coutName剩余时间 Time优先数 Level; if(cur-Time=0) cout状态 为完成态endl; delete cur; else cout状态 为就绪态next) if(cur-Level p-next-Level )break; p=p-next ; cur-next=p-next; p-next=cur; coutnext) coutnext-Namenext ; coutnext =NULL; Init(Head); while(Head-next ) Run(Head); return 0;