Program To Implement Shortest Job First (Preemptive)
Program To Implement Shortest Job First (Preemptive)
#include <iostream>
int temp;
ari[0] = 0;
bt[0] = 0;
for(int i=0;i<n-1;i++)
for(int j=0;j<n;j++)
if(ari[j]>ari[j+1])
temp = ari[j];
ari[j] = ari[j+1];
ari[j+1] = temp;
temp = p[j];
p[j] = p[j+1];
p[j+1] = temp;
temp = bt[j];
bt[j] = bt[j+1];
bt[j+1] = temp;
}
int temp;
for(int i=2;i<n;i++)
for(int j=2;j<n;j++)
if(bt[j]>bt[j+1])
temp = bt[j];
bt[j] = bt[j+1];
bt[j+1] = temp;
temp = ari[j];
ari[j] = ari[j+1];
ari[j+1] = temp;
temp = p[j];
p[j] = p[j+1];
p[j+1] = temp;
}
}
int ct[10],wt[10],tat[10];
ct[0] = 0;
wt[0] = 0;
tat[0] = 0;
sortbt(n,ari,bt,p);
cout<<"\n\npno.\tAt\tBt\tCt\tTat\tWt\n";
for(int i=0;i<n;i++)
}
int main()
int n,p[10],ari[10],bt[10];
ari[0] = 0;
bt[0] = 0;
cin>>n;
for(int i=0;i<n;i++)
p[i+1]=i;
cin>>bt[i+1];
cin>>ari[i+1];
fix(n,ari,bt,p);
func(n,ari,bt,p);
return 0;
}
PROGRAM TO IMPLEMENT ROUND ROBIN
#include <iostream>
#include<conio.h>
int
at[50],bt[50],ct[50]={0},qt,rqi[50]={0},c=0,st,flg=0,tm=0,noe=0,pnt=0,btm[50]={
0},tt,wt;
float att,awt;
int main()
int n;
cin>>n;
for(int i=0;i<n;i++)
cout<<"\nprocess"<<i+1;
cout<<"\nAt = ";
cin>>at[i];
cout<<"Bt = ";
cin>>bt[i];
btm[i]=bt[i];
cin>>qt;
cout<<"\nGANTT chart\n"<<at[0];
do
if(flg==0)
st=at[0];
if(btm[0]<=qt)
tm=st+btm[0];
btm[0]=0;
searchStack01(pnt,tm,n);
else
{
btm[0]=btm[0]-qt;
tm=st+qt;
searchStack01(pnt,tm,n);
addqueue(pnt);
else
pnt=rqi[0]-1;
st=tm;
for(int x=0;x<noe;x++)
rqi[x]=rqi[x+1];
noe--;
if(btm[pnt]<=qt)
tm=st+btm[pnt];
btm[pnt]=0;
searchStack02(pnt,tm,n);
else
{
btm[pnt]=btm[pnt]-qt;
tm=st+qt;
searchStack02(pnt,tm,n);
addqueue(pnt);
if(btm[pnt]==0)
ct[pnt]=tm;
flg++;
cout<<"]-p"<<pnt+1<<"-["<<tm;
} while(noe!=0);
cout<<"\n\nProcess\tAT\tBT\tCT\tTT\tWT\n";
for(int x=0;x<n;x++)
tt=ct[x]-at[x];
wt=tt-bt[x];
cout<<"p"<<x+1<<"\t"<<at[x]<<"\t"<<bt[x]<<"\t"<<ct[x]<<"\t"<<tt<<"\t"<<wt<
<"\n";
awt=awt+wt;
att=att+tt;
cout<<"\naverage tt:"<<att/n;
cout<<"\naverage wt:"<<awt/n;
return 0;
for(int x=pnt+1;x<n;x++)
if(at[x]<=tm)
rqi[noe]=x+1;
noe++;
}
void searchStack02(int pnt,int tm,int n)
for(int x=pnt+1;x<n;x++)
int fl=0;
for(int y=0;y<noe;y++)
if(rqi[y]==x+1)
fl++;
if(at[x]<=tm&&fl==0&&btm[x]!=0)
rqi[noe]=x+1;
noe++;
rqi[noe]=pnt+1;
noe++;