操作系统课程设计-模拟时间片轮转法实现处理器调度|精品课程网站设计|课程设计网报告总结心得#include
#include #include #include class List;class PCB{public: friend class List;private: PCB (char p[],int t){strcpy(pname,p);runnedtime=0;requesttime=t;status='R';next=NULL;} char pname[2]; int runnedtime; int requesttime; char status; PCB* next;};class List{public: List(char p[]="Q1",int t=0){list=new PCB(p,t);pc=list;time=0;} int print(); int append(char p[],int t); void insert(char p[],int t); void run(); void link(); int length();private: PCB *list; PCB *end(); PCB *pc; int time;};int List::length(){ int cnt=0; PCB *pt=list; for(;pt->next!=list;pt->next,cnt++) ; return cnt;}void List::link(){ if(list!=NULL) (end())->next=list;}void List::insert(char p[],int t){ PCB *pt=new PCB(p,t); pt->next=list; list=pt;}int List::append(char p[],int t){ PCB *pt=new PCB(p,t); if(list==NULL) list=pt; else { (end())->next=pt; } return 1;}PCB *List::end(){ PCB *prv,*pt; for(prv=pt=list;pt;prv=pt,pt=pt->next) ; return prv;}int List :: print(){ time++; if(list==0) return 0; PCB *pt=list; cout<<"name run_time req_time state"<pname[0]<pname[1]<<" "; cout<runnedtime<<" "; cout<requesttime<<" "; cout<status<<" "; cout<next; } getch(); return 1;}void List:: run(){ for(;pc;) { PCB *pt=list; cout<<"********************************************"<pname<runnedtime+=1; if(pc->runnedtime==pc->requesttime) { pc->status='E'; cout<<"******************************************"<pname<<"运行时间已满,退出队列!"<next; pc=pc->next; } else { for(;pt->next!=pc;pt=pt->next) ; if(pc->next!=NULL) { pt->next=pc->next; pc=pc->next; } else { pt->next=NULL; pc=list; } } } else { if(pc->next!=NULL) pc=pc->next; else pc=list; } print(); } }void main(){ cout<<"**********************模拟时间片轮转法实现处理器调度************************"<