Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- struct gt
- {
- int pro;
- int time;
- };
- vector<gt>v;
- int arr[1000], bur[1000], wt[1000];
- int main()
- {
- int n, i, j, k, x, y;
- printf("Enter number of processes : ");
- cin>>n;
- int arrTemp[1000];
- int burTemp[1000];
- int process[1000];
- for(i=0; i<n; i++){
- printf("Enter burst time and arrival time of p%d : ", i);
- cin>>bur[i]>>arr[i];
- process[i]=i;
- arrTemp[i]=arr[i];
- burTemp[i]=bur[i];
- }
- for(i=0; i<n; i++){
- for(j=i+1; j<n; j++){
- if(arrTemp[i]>arrTemp[j]){
- swap(arrTemp[i], arrTemp[j]);
- swap(burTemp[i], burTemp[j]);
- swap(process[i], process[j]);
- }
- }
- }
- wt[process[0]]=0;
- printf("\n\t\t****Gantt Chart****\n");
- printf("%d__[p%d]__%d ", arrTemp[0], process[0], arrTemp[0]+burTemp[0]);
- int presentTime=arrTemp[0]+burTemp[0];
- double sum=0.0;
- for(i=1; i<n; i++){
- int strt, endd;
- if(presentTime>arrTemp[i]){
- wt[i]=presentTime-arrTemp[i];
- strt=presentTime;
- endd=presentTime+burTemp[i];
- presentTime=endd;
- }
- else{
- wt[i]=0;
- strt=arrTemp[i];
- endd=arrTemp[i]+burTemp[i];
- presentTime=endd;
- }
- printf("%d__[p%d]__%d ", strt, process[i], endd);
- sum+=(double)wt[i];
- }
- printf("\n\n");
- printf("\t****Individual Waiting time****");
- printf("\n\n Process Waiting time\n");
- for(i=0; i<n; i++){
- printf(" p%d %d\n", i, wt[i]);
- }
- printf("\n\nAverage of waiting time : %.2lf\n", sum/n);
- }
Add Comment
Please, Sign In to add comment