发布网友 发布时间:2022-04-29 19:33
共2个回答
热心网友 时间:2022-06-21 13:41
#include#include#include#includeusingnamespacestd;typedefstructProcess{stringid;intarrive_time;intsever_time;intfinish_time;intturnover_time;Process*next;}Process,*Linkp;classFCFS_schele{public:FCFS_schele(){Creat_queue();}~FCFS_schele();voidCreat_queue();voidInsert_queue();voidorderInsert_queue();voidOut_queue();voidPrintall();voidSort_queue();ProcessGethead();private:Linkphead,tail;intnum;ProcessCreat_process();};///////////////////////////////////////////////////////方法的具体实现voidFCFS_schele::Creat_queue(){head=newProcess;head->next=0;tail=head;num=0;}ostream&operatora.id;cout>a.arrive_time;cout>a.sever_time;a.finish_time=0;a.turnover_time=0;a.next=0;return(a);}voidFCFS_schele::Insert_queue(){Linkpp;p=newProcess;*p=Creat_process();if(num==0){p->finish_time=p->arrive_time+p->sever_time;p->turnover_time=p->finish_time-p->arrive_time;}else{p->finish_time=tail->finish_time+p->sever_time;p->turnover_time=p->finish_time-p->arrive_time;}tail->next=p;tail=p;num++;}voidFCFS_schele::Out_queue()//进程调度出队{Linkpp;p=head->next;if(!p)coutnext=p->next;if(p->next==NULL)tail=head;coutnext;if(p)return(*p);elsethrow1;//当队空无法返回Process类型返回值时抛出异常错误整形值1}voidFCFS_schele::Printall()//打印进程队列所有进程信息{Linkpp;floatsum_wghtime=0;p=head->next;coutturnover_time)/float(p->sever_time)turnover_time/p->sever_time;p=p->next;}coutnext;location=track->next;while(location&&location->next){record=search=location;while(search){if(search->sever_timesever_time)record=search;search=search->next;}if(record!=location){temp=*record;record->arrive_time=location->arrive_time;record->id=location->id;record->sever_time=location->sever_time;location->id=temp.id;location->sever_time=temp.sever_time;location->arrive_time=temp.arrive_time;location->finish_time=track->finish_time+location->sever_time;location->turnover_time=location->finish_time-location->arrive_time;}track=location;location=location->next;}if(tail==location){tail->finish_time=track->finish_time+tail->sever_time;tail->turnover_time=tail->finish_time-tail->arrive_time;}}FCFS_schele::~FCFS_schele(){Linkpp;while(p=head){head=head->next;deletep;}coutnext=p;tail=p;p->finish_time=p->arrive_time+p->sever_time;p->turnover_time=p->finish_time-p->arrive_time;}else{pr=head->next;while(pr->next&&p->sever_time>=pr->next->sever_time)pr=pr->next;if(pr->next==0){p->finish_time=tail->finish_time+p->sever_time;p->turnover_time=p->finish_time-p->arrive_time;tail->next=p;tail=p;}else{p->next=pr->next;pr->next=p;while(p){p->finish_time=pr->finish_time+p->sever_time;p->turnover_time=p->finish_time-p->arrive_time;pr=p;p=p->next;}}}num++;}voidmain(){//DWORDstart=GetTickCount();FCFS_scheleos;os.orderInsert_queue();os.orderInsert_queue();os.orderInsert_queue();os.orderInsert_queue();os.orderInsert_queue();//os.orderInsert_queue();//os.orderInsert_queue();os.Printall();//os.Sort_queue();os.Sort_queue();os.Printall();os.Out_queue();os.Out_queue();os.Out_queue();os.Out_queue();/*try{cout<热心网友 时间:2022-06-21 13:41
无论是在批处理系统还是分时系统中,用户进程数一般都多于处理机数、这将导致它们互相争夺处理机。另外,系统进程也同样需要使用处理机。这就要求进程调度程序按一定的策略,动态地把处理机分配给处于就绪队列中的某一个进程,以使之执行。