-
Notifications
You must be signed in to change notification settings - Fork 7
/
round robin without arrival time.cpp
128 lines (115 loc) · 2.1 KB
/
round robin without arrival time.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include<stdio.h>
#include<stdlib.h>
int main(){
int no_of_processes;
printf("Enter number of processes : ");
scanf("%d",&no_of_processes);
printf("\n");
int* bt=(int*)malloc(no_of_processes*sizeof(int));
int* bt1=(int*)malloc(no_of_processes*sizeof(int));
int* ct=(int*)malloc(no_of_processes*sizeof(int));
int index,tq,c,r=0,f=0;
int rq[100][2];
printf("Enter time quantum/time stamp: ");
scanf("%d",&tq);
printf("\nbt\n");
for(int i=0; i<no_of_processes; i++){
scanf("%d",&bt[i]);
bt1[i]=bt[i];
}
printf("\n");
// printing the burst time
for(int j=0; j<no_of_processes; j++){
printf("%d\n",bt[j]);
}
printf("\n");
// complete time
if(bt[0]>tq){
c=tq;
bt[0]=bt[0]-tq;
ct[0]=c;
rq[r][0]=c;
rq[r][1]=0;
r++;
}
else{
c=bt[0];
ct[0]=c;
}
int i=1;
while(i<no_of_processes){
if(r!=0){ //
if(bt[i]>tq){
c=c+tq;
ct[i]=c;
bt[i]=bt[i]-tq;
rq[r][0]=c;
rq[r][1]=i;
r++;
}
else{
c=c+bt[i];
ct[i]=c;
}
i++;
}
else if(r==0){
if(bt[i]>tq){
c=c+tq;
bt[i]=bt[i]-tq;
rq[r][0]=ct[i];
rq[r][1]=i;
r++;
}
else{
c=c+bt[i];
ct[i]=c;
}
i++;
}
else{
index=rq[f][1];
f++;
if(bt[index]>tq){
c=c+tq;
ct[index]=c;
bt[index]=bt[index]-tq;
rq[r][0]=ct[index];
rq[r][1]=index;
r++;
}
else{
c=c+bt[index];
ct[index]=c;
}
}
}
while(f<r){
index=rq[f][1];
f++;
if(bt[index]>tq){
c=c+tq;
ct[index]=c;
bt[index]=bt[index]-tq;
rq[r][0]=ct[index];
rq[r][1]=index;
r++;
}
else{
c=c+bt[index];
ct[index]=c;
}
}
int* tat=(int*)malloc(no_of_processes*sizeof(int));
for(int i=0; i<no_of_processes; i++){
tat[i]=ct[i];
}
int* wt=(int*)malloc(no_of_processes*sizeof(int));
for(int i=0; i<no_of_processes; i++){
wt[i]=tat[i]-bt1[i];
}
printf("at bt ct tat wt\n");
for(int i=0; i<no_of_processes; i++){
printf("%d\t%d\t%d\t%d\t%d\n",0,bt1[i],ct[i],tat[i],wt[i]);
}
}