Implementing SJF in C++

Here is C++ implementation of Shortest Job First (SJF) algorithm.

#include
#include
struct process
{
int no;
int at;
int et;
int wt;
int tt;
};

void main()
{
clrscr();
process p[4];
int i,j;

for(i=0;i<4;i++) { cout<<"\n Enter arrival time of P"<>p[i].at;
cout<<"\n Enter execution time of P"<>p[i].et;
p[i].no=i;
}

cout<<"\n PNO\tAT\tET"; for(i=0;i<4;i++) { cout<<"\n P"<p[j].et)
{
temp=p[i];
p[i]=p[j];
p[j]=temp;
}
}
}
p[0].wt=0;
p[0].tt=p[0].et;
int tte=p[0].et;

for(i=1;i<4;i++) { p[i].wt=p[i-1].wt+p[i-1].et-(p[i].at-p[i-1].at); p[i].tt=p[i].wt+p[i].et; tte=tte+p[i].et; } cout<<" \n Result"; cout<<"\n PNO\tAT\tWT\tET\tTT"; for(i=0;i<4;i++) { cout<<"\n P"<

Leave a Reply

Your email address will not be published. Required fields are marked *