Disk Scheduling algo-FCFS and SCAN
Disk Scheduling algo-FCFS and SCAN
h>
#include <stdlib.h>
// Reverse direction
printf("Move from %d to %d\n", current_position, sorted_requests[n - 1]);
total_head_movement += abs(current_position - sorted_requests[n - 1]);
current_position = sorted_requests[n - 1];
int main() {
int requests[MAX_REQUESTS];
int n, head;
if (n > MAX_REQUESTS) {
printf("Error: Maximum requests exceeded.\n");
return 1;
}
printf("Enter the requests:\n");
for (int i = 0; i < n; i++) {
scanf("%d", &requests[i]);
}
fcfs(requests, n, head);
printf("\n");
scan(requests, n, head);
return 0;
}
Enter the number of requests: 8
Enter the requests:
98
183
37
122
14
124
65
67
Enter the initial head position: 53
FCFS Scheduling Order:
Move from 53 to 98
Move from 98 to 183
Move from 183 to 37
Move from 37 to 122
Move from 122 to 14
Move from 14 to 124
Move from 124 to 65
Move from 65 to 67
Total head movement: 278