LOOK Disk Scheduling
#include <stdio.h>
#include <stdlib.h>
int main() {
int n, i, j, head, seek_time = 0, prev, curr;
printf("Enter the number of requests: ");
scanf("%d", &n);
int requests[n];
printf("Enter the requests: ");
for(i = 0; i < n; i++) {
scanf("%d", &requests[i]);
}
printf("Enter the initial head position: ");
scanf("%d", &head);
prev = head;
for(i = 0; i < n; i++) {
int closest = 999999;
for(j = 0; j < n; j++) {
if(abs(requests[j] - prev) < closest) {
closest = abs(requests[j] - prev);
curr = requests[j];
}
}
seek_time += abs(curr - prev);
prev = curr;
}
printf("Total seek time: %d\n", seek_time);
return 0;
}
#include <stdlib.h>
int main() {
int n, i, j, head, seek_time = 0, prev, curr;
printf("Enter the number of requests: ");
scanf("%d", &n);
int requests[n];
printf("Enter the requests: ");
for(i = 0; i < n; i++) {
scanf("%d", &requests[i]);
}
printf("Enter the initial head position: ");
scanf("%d", &head);
prev = head;
for(i = 0; i < n; i++) {
int closest = 999999;
for(j = 0; j < n; j++) {
if(abs(requests[j] - prev) < closest) {
closest = abs(requests[j] - prev);
curr = requests[j];
}
}
seek_time += abs(curr - prev);
prev = curr;
}
printf("Total seek time: %d\n", seek_time);
return 0;
}
Comments
Post a Comment