求个进程调度高响应比优先权算法,不会计算优先权
#include<iostream>using namespace std;
typedef struct PCB
{
int id; //进程名字p1、p2、p3、p4、p5
struct PCB *next;//指针指向下一个位置
float runtime; //到达时间
float priority;//优先级
float stime;//服务时间
}*pcb;
void create(PCB *h)
{
float a,c; //a运行时间、b进程优先级
PCB *q,*p;
h->next=NULL;
p=h;
for(int i=0;i<5;i++)
{
cout<<"-------P"<<i+1<<" :"<<endl;
cin>>a>>c;
q=new PCB;
q->id=i+1;
q->runtime=a;
q->stime=c;
p->next=q;
p=q;
}
p->next=NULL;
}
float priority(PCB *h)
{
PCB *s;
s=h->next;
while(s!=NULL)
{
//s->next->wtime=(s->stime-s->next->runtime);
s->next->priority=(1+(s->stime-s->next->runtime))/s->next->stime;
s=s->next;
return s->next->priority;
}
}
void display(PCB *h)
{
PCB *s=h->next;
while(s!=NULL)
{ cout<<"runtime"<<" "<<"stime"<<" "<<"priority"<<endl;
cout<<s->runtime<<" "<<s->stime<<" "<<s->priority<<endl;
s=s->next;
}
}
int main()
{ PCB *h=new PCB;
create(h);
//priority(h);
display(h);
cout<< priority(h)<<" ";
return 0;
}