-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdisk_schedule.c
More file actions
95 lines (65 loc) · 1.16 KB
/
disk_schedule.c
File metadata and controls
95 lines (65 loc) · 1.16 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int head, total, n;
int a[20], b[20];
void fcfs();
void sort();
//void sstf();
int main(){
int i;
system("cls");
printf("\nEnter the head element - ");
scanf("%d", &head);
printf("\nEnter the total no of cylinders - ");
scanf("%d", &total);
printf("\nEnter no of elements - ");
scanf("%d", &n);
printf("\nEnter elements one by one - ");
for(i = 0; i < n; i++)
scanf("%d", &a[i]);
sort();
fcfs();
//sstf();
}
void sort(){
int i,j, temp;
for(i = 0; i < n; i++) b[i] = a[i];
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(b[i] < b[j]){
temp = b[i];
b[i] = b[j];
b[j] = temp;
}
}
}
for(i = 0; i < n; i++) printf("%d-", a[i]);
}
void fcfs(){
int i,curr, total=0;
curr = head;
for(i = 0; i < n; i++){
total += abs(a[i] - curr);
curr = a[i];
}
printf("FCFS - Total Cylinders - %d", total);
}
/*void sstf(){
int curr, i = 0, visited = 0;
visited[20] = 0;
while(1){
if(b[i] == head){
curr = head;
break;
}
i++;
}
while(visited != n){
if((b[i] - b[i-1]) < (a[i+1] - a[i])){
}
else{
curr = a[i+1];
}
}
}*/