2. Shortest Job First (SJF) non primitive scheduling program in C

  1. Shortest Job First (SJF) non primitive scheduling program in c

#include<stdio.h>
int at[50],bt[50];
int n;
int save;
int temp [50],k;
void input()
{
for( int i = 0 ; i < n ; i++)
{
// printf(“\nEnter the BT “);
scanf(“%d”,&at[i]);
scanf(“%d”,&bt[i]);
if(at[i]==0)
save = i ;
}
}
int mi,iSave;
void min(int bt,int i_save)
{
if( mi > bt)
{
mi = bt;
iSave = i_save;
}
}
int total;
int ar[50];
int to ;
int wtSave1,wtSave2;
void WTcalculation()
{
wtSave1 = ar[iSave];
wtSave2 = iSave;
ar[iSave] = to -at[iSave];

}
void calculation()
{
to =0;
int teSaveBT =bt[save];
total = bt[save];
printf(“\n0”);
bt[save] = -2;
to = total;
iSave = save;
for(int j = 0 ; j < n; j++ )
{
mi=129350;
printf(“—p%d—%d”,iSave+1,total );
for(int i = 0 ; i < teSaveBT; i++ )
{
if(bt[i]==-2)
continue;
if(bt[i]==0)
break;

min( bt[i],i);
}

to =total;
WTcalculation();
total = total + bt[iSave];

teSaveBT = total;
bt[iSave] = – 2 ;

}

}
void output()
{
for( int i = 0 ; i < n ; i++)

{
if(wtSave2 == i)
{
printf(“\nWTP%d = %d”,i+1,wtSave1);
continue;
}
printf(“\nWTP%d = %d”,i+1,ar[i]);
}
}
int main()
{

scanf(“%d”,&n);
input();
calculation();
output();
return 0;
}

Sample Input :

4
0 8
1 4
2 9
3 5

Sample Output :

1