短作业优先算法用c语言如何写?

来源:百度知道 编辑:UC知道 时间:2024/06/11 05:57:23

这样写应该可以:
#include<iostream.h>

#include<stdio.h>
struct pcb{
char pno;
int come_time; //到达时间
int run_time; //服务时间
};
float fcfs(pcb pro[],int n)
{
struct pcb temp;
int i,j,k; //time为当前时间
float weight_time=0,time=0; //记录周转时间的和
//temp=(pcb)malloc(sizeof(pcb));
cout<<"进程调度情况如下:"<<endl;
cout<<"进程号 到达时间 服务时间 周转时间:"<<endl;
//选择排序过程,按到达时间升序排列
for(i=0;i<n-1;i++)
{
k=i;
for(j=i+1;j<n;j++)
if(pro[k].come_time>pro[j].come_time)
k=j;
if(k!=i)
{
temp=pro[i];
pro[i]=pro[k];
pro[k]=temp;
}
}
for(i=0;i<n;i++)
{ time+=pro[i].run_time;
weight_time+=(time-pro[i].come_time)/pro[i].run_time; //(time-pro[i].come_time)/pro[i].run_time为排