#include
using namespace std;
typedef struct PCB
{
char id; //进程名字p1、p2、p3、p4、p5
struct PCB *next;//指针指向下一个位置
float runtime; //到达时间
float priority;//优先级
float wtime;
float stime;//服务时间
int flag;
}*pcb;
void create(PCB *h)
{
float a,c; //a运行时间、b进程优先级
char d;
PCB *q,*p;
h->next=NULL;
p=h;
for(int i=0;i<5;i++)
{
cout<
cin>>d>>a>>c;
q=new PCB;
q->id=d;
q->runtime=a;
q->stime=c;
q->flag=1;
p->next=q;
p=q;
}
p->next=NULL;
}
void priority(PCB *h)
{
PCB *s,*s1,*s2;
s=h->next;
cout<id;
float cur=0;
float cur1=0;
cur+=s->stime;
s->flag=0;
s=s->next;
s1=s;
s2=s;
int i=4;
while(i)
{ s=s2;
s1=s2;
while(s!=NULL)
{ if(s->flag==1)
{
s->priority=1+(cur-s->runtime)/s->stime;
if((s->priority>cur1))
cur1=s->priority;
}
s=s->next;
}
while(s1!=NULL)
{ if((s1->priority==cur1)&&(s1->flag==1))
{
cout<id;
s1->flag=0;
cur+=s1->stime;
cur1=0;
}
s1=s1->next;
}
i--;
}
}
void display(PCB *h)
{
PCB *s=h->next;
while(s!=NULL)
{ cout<
cout<runtime<stime<priority<
s=s->next;
}
}
int main()
{ PCB *h=new PCB;
create(h);
priority(h);
//display(h);
//cout<< priority(h)<
return 0;
}

同学习......同进步....你帮我......我帮你.....上善若水.....
7934




被折叠的 条评论
为什么被折叠?



