-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscan.c
More file actions
63 lines (62 loc) · 1.34 KB
/
Copy pathscan.c
File metadata and controls
63 lines (62 loc) · 1.34 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
#include <stdio.h>
int head, a[20], i, distance, n, seektime, size;
void bubbleSort(int arr[], int n) {
int temp;
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
int main() {
printf("\nEnter Head position: ");
scanf("%d", &head);
printf("\nEnter number of disk requests: ");
scanf("%d", &n);
printf("\nEnter the disk size: ");
scanf("%d", &size);
printf("\nEnter the disk requests: ");
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
a[n] = head;
n++;
bubbleSort(a, n);
int pos;
for (i = 0; i < n; i++) {
if (a[i] == head) {
pos = i;
break;
}
}
printf("\n\tSCAN DISK SCHEDULING\n\n");
for (i = pos; i < n - 1; i++) {
distance = a[i + 1] - a[i];
printf("Head movement from %d to %d : %d\n", a[i], a[i + 1],
distance);
seektime += distance;
}
if (a[n - 1] != size - 1) {
distance = size - 1 - a[n - 1];
printf("Head movement from %d to %d : %d\n", a[n - 1], size - 1,
distance);
seektime += distance;
}
if (pos > 0) {
printf("Head movement from %d to %d : %d\n", size - 1, a[pos -
1], size - 1 - a[pos - 1]);
seektime += size - 1 - a[pos - 1];
for (i = pos - 1; i > 0; i--) {
distance = a[i] - a[i - 1];
printf("Head movement from %d to %d : %d\n", a[i], a[i -
1], distance);
seektime += distance;
}
}
printf("\nTotal seek time is : %d\n", seektime);
return 0;
}