SJF(最短作业优先)
#include<stdio.h>
#include<stdlib.h>
#define N 100
typedef struct process
{
int num;
int time;
int start;
int end;
int begin;
int freetime;
int arrivetime;
int finish;
int turn;
double average;
}P;
P a[N],b;
int wordtime=0;
void sjf(int i,int j,int t,int n){
a[0].finish=a[0].arrivetime+a[0].freetime;//给予a[0]初值
wordtime=a[0].finish;
a[0].turn=a[0].time;
a[0].average=(float)a[0].turn/a[0].time;
for(i=1;i<n;i++)//执行
{
for(j=i+1;j<n;j++)
{
if(a[j].arrivetime<=a[i-1].finish)
{
for(t=i;t<=j;t++)
{
if(a[t].time>a[j].time)
{
b=a[j];
a[j]=a[t];
a[t]=b;
}
}
}
}
if(a[i].arrivetime<a[i-1].finish)
{
a[i].finish=a[i-1].finish+a[i].freetime;
a[i].turn=a[i].finish-a[i].arrivetime;
}
else
{
a[i].finish=a[i].arrivetime+a[i].freetime;
a[i].turn=a[i].time;
}
a[i].average=(float)a[i].turn/a[i].time;
wordtime=a[i].finish;
}