SJF- Operating System
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter process : "<<endl;
cin>>n;
int bt[n], pn[n];
for(int i=0; i<n; i++){
cout<<"Enter process "<<i+1<<" : ";
cin>>bt[i];
pn[i]=i+1;
}
for(int i=0; i<n; i++){
for(int j=i+1; j<n; j++){
if(bt[i]>bt[j]){
int temp = bt[i];
bt[i] = bt[j];
bt[j] = temp;
temp = pn[i];
pn[i] = pn[j];
pn[j] = temp;
}
}
}
int wt=0;
for( int i=0; i<n; i++){
cout<<"Waiting Time "<<pn[i]<<" : "<<wt<<endl;
wt += bt[i];
}
return 0;
}
0 Comments