Program to implement Shortest Job First (preemptive) #include
using namespace std; void fix(int n,int ari[],int bt[],int p[]) { int temp; ari[0] = 0; bt[0] = 0; for(int i=0;iari[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;
} } } } void sortbt(int n,int ari[],int bt[],int p[]) { int temp; for(int i=2;ibt[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; }
} } } void func(int n,int ari[],int bt[],int p[]) { int ct[10],wt[10],tat[10];
ct[0] = 0; wt[0] = 0; tat[0] = 0; ct[0+1] = ct[0] + bt[0+1]; tat[0+1] = ct[0+1] - ari[0+1]; wt[0+1] = tat[0+1] - bt[0+1]; sortbt(n,ari,bt,p); cout<<"\n\npno.\tAt\tBt\tCt\tTat\tWt\n"; for(int i=0;i
int main() { int n,p[10],ari[10],bt[10]; ari[0] = 0; bt[0] = 0; cout<<"enter number of processes:"; cin>>n; for(int i=0;i>bt[i+1]; cout<<"enter arrival time:"; cin>>ari[i+1]; } fix(n,ari,bt,p); func(n,ari,bt,p); return 0; }
PROGRAM TO IMPLEMENT ROUND ROBIN #include #include using namespace std; void searchStack01(int pnt,int tm,int n); void searchStack02(int pnt,int tm,int n); void addqueue(int pnt); 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; cout<<"enter number of processes:"; cin>>n; cout<<"round robin algo:input 5 processes\n"; cout<<"\n\t\there some attrib use in program\n"; cout<<"At = arrival time\nBt = burst time\nTT = turn arround time\nWt = waiting time\n\n"; for(int i=0;i
cout<<"\nAt = "; cin>>at[i]; cout<<"Bt = "; cin>>bt[i]; btm[i]=bt[i]; } cout<<"enter time quamtum:"; cin>>qt; cout<<"\nGANTT chart\n"<
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"<
while(noe!=0);
cout<<"\n\nProcess\tAT\tBT\tCT\tTT\tWT\n"; for(int x=0;x
cout<<"p"<<x+1<<"\t"<
void searchStack01(int pnt,int tm,int n) { for(int x=pnt+1;x
void searchStack02(int pnt,int tm,int n) { for(int x=pnt+1;x
void addqueue(int pnt)
{ rqi[noe]=pnt+1; noe++; }