Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int bt[20],p[20],i,j,total=0,pos,temp,number,store =0;;
- float avrgwait=0;
- cout<<"Enter the number of process: ";
- cin>>number;
- int burst[number+1], wait[number+1], turnar[number];
- wait[0]=0;
- for(i=1; i<=number; i++)
- {
- cout<<"Input Burst Time for P"<<i<<" : ";
- cin>>burst[i];
- }
- //sorting burst time in ascending order using selection sort
- for(i=0;i<number;i++)
- {
- pos=i;
- for(j=i+1;j<number;j++)
- {
- if(burst[j]<burst[pos])
- pos=j;
- }
- temp=burst[i];
- burst[i]=burst[pos];
- burst[pos]=temp;
- temp=p[i];
- p[i]=p[pos];
- p[pos]=temp;
- }
- cout<<"The Brust Time In ascending "<<endl;
- for(i=1; i<=number; i++){
- cout<<"Brust for P"<<i<<":"<<burst[i]<<endl;
- }
- for(i=1; i<=number; i++)
- {
- store = wait[i-1] + burst[i];
- wait[i] = store;
- avrgwait = avrgwait + wait[i-1];
- cout<<"Waiting time for P"<<i<<" : "<<wait[i-1]<<endl;
- }
- for(i=0; i<number; i++)
- {
- turnar[i] = wait[i+1];
- cout<<"Turn around time P"<<i+1<<" : "<<turnar[i]<<endl;
- }
- cout<<"Average wait time: "<<avrgwait/number<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement