91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 2KB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發布日期: 2021-05-21
  • 語言: C/C++
  • 標簽:

資源簡介

里面是輪詢調度算法的簡單代碼,沒有其它內容,編寫語言c++

資源截圖

代碼片段和文件信息

#include?“roundrobin.h“
#include
#include
using?namespace?std;
roundrobin::roundrobin(void)
{
rq=w=t=NULL;
}

roundrobin::~roundrobin(void)
{
if(rq!=NULL)
{
delete[]?rq;
delete[]?w;
delete[]?t;
delete[]?a;
}
}
int?roundrobin::read()//read?input?from?the?user
{
int?i;
cout<<“Enter?number?of?processes:“;
cin>>n;
if(rq!=NULL)
{
delete[]?rq;
delete[]?w;
delete[]?t;
}
try
{
rq=new?int[n];
w=new?int[n];
t=new?int[n];
a=new?int[n];
}
catch(bad_alloc?&ba)
{
cerr< exit(1);
}
cout<<“Enter?arrival?times:\n“;
for(i=0;i {
cin>>a[i];
}
cout<<“Enter?request?times:\n“;
for(i=0;i {
cin>>rq[i];
w[i]=t[i]=0;
}
cout<<“Enter?time?quantum:“;
cin>>q;
return?1;
}
void?roundrobin::calc()//to?calculate?turn-around?and?wait?times?of?all?processes?and?the?ordering
{
int?j=0;
int time;
int?k;
int?i;
int?*r;//remaining?times
try
{
r=new?int[n];
}
catch(bad_alloc?&ba)
{
cerr< exit(1);
}
for(i=0;i bool?f=false;//flag?to?indicate?whether?any?process?was?scheduled?as?i?changed?from?0?to?n-1?in?the?next?for?loop
int?sp=0;//time?spent
for(i=0;j {
if(r[i]>0&&sp>=a[i])//find?the?next?uncompleted?process?which?has?already?or?just?arrived
{
f=true;
if(r[i]<=q)//if?the?process?requests?for?time?less?than?the?quantum
time=r[i];//time?to?be?alloted?in?this?turn?is?the?complete?requested?time
else time=q;//else?it?is?the?quantum?time
//schedule?the?process
t[i]+=timer[i]-=timeorder.push_back(i+1);
if(r[i]==0) j++;//if?the?process?has?got?completed?increment?j
for(k=0;k if(r[k]!=0&&k!=i&&a[k] if(!(a[k]<=sp))//if?they?arrived?while?scheduling?this?process
w[k]+=sp+time-a[k]t[i]+=sp+time-a[k];//account?for?the?time?they?spent?waiting?while?the?process?was?being?scheduled
else
w[k]+=timet[k]+=time;//add?time?to?their?wait?times?and?turn-around?times
sp+=time;
continue;
}
if(i==n-1)
{
if(!f)
//now?there?are?no?more?arrived?processes?to?be?scheduled
//so?change?sp?to?the?arrival?time?of?next?arriving?process
{
int?it;
int?diff=0;//diff?between?present?time?spent?and?arrivaltime?of?next?arriving?process
for(it=0;it if(sp {
if(diff==0) diff=a[it]-sp;
else?if(diff>a[it]-sp) diff=a[it]-sp;
}
sp+=diff;
}
f=false;
}
}
delete[]?r;
}
void?roundrobin::display()
{
int?i;
float?tav=0;//average?turn-around?time
float?wav=0;//average?wait?time
for(i=0;i tav+=t[i]wav+=w[i];
tav/=nwav/=n;
cout<<“Scheduling?order:\n“;
list::iterator?oi;
for(oi=order.begin();oi!=order.end();

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????????204??2007-02-10?08:46??RR.cpp
?????文件????????3117??2007-02-10?11:46??roundrobin.cpp
?????文件?????????496??2007-02-10?08:46??roundrobin.h

評論

共有 條評論

相關資源