-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfcfs_disk.c
44 lines (32 loc) · 838 Bytes
/
fcfs_disk.c
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
#include <stdio.h>
int size = 8;
void FCFS(int arr[], int head)
{
int seek_count = 0;
int distance, cur_track;
for (int i = 0; i < size; i++) {
cur_track = arr[i];
// calculate absolute distance
distance = abs(cur_track - head);
// increase the total count
seek_count += distance;
// accessed track is now new head
head = cur_track;
}
printf("Total number of seek operations = %d\n",seek_count);
// Seek sequence would be the same
// as request array sequence
printf("Seek Sequence is\n");
for (int i = 0; i < size; i++) {
printf("%d\n" ,arr[i]);
}
}
// Driver code
int main()
{
// request array
int arr[] = { 176, 79, 34, 60, 92, 11, 41, 114 };
int head = 50;
FCFS(arr, head);
return 0;
}