-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShortestSeekTimeFirst.c
74 lines (72 loc) · 2.27 KB
/
ShortestSeekTimeFirst.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
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
#include<stdio.h>
struct head
{
int num;
int flag;
};
int main()
{
struct head h[33];
int array_1[33], array_2[33];
int count = 0, j, x, limit, minimum, location, disk_head, sum = 0;
printf("\nEnter total number of locations:\t");
scanf("%d", &limit);
printf("\nEnter position of disk head:\t");
scanf("%d", &disk_head);
printf("\nEnter elements of disk head queue\n");
for(count = 0;count<limit;count++)
{
scanf("%d", &h[count].num);
h[count].flag = 0;
}
for(count = 0; count < limit; count++)
{
x = 0;
minimum = 0;
location = 0;
for(j = 0; j < limit; j++)
{
if(h[j].flag == 0)
{
if(x == 0)
{
array_1[j] = disk_head - h[j].num;
if(array_1[j] < 0)
{
array_1[j] = h[j].num - disk_head;
}
minimum = array_1[j];
location = j;
x++;
}
else
{
array_1[j] = disk_head - h[j].num;
if(array_1[j] < 0)
{
array_1[j] = h[j].num - disk_head;
}
}
if(minimum > array_1[j])
{
minimum = array_1[j];
location = j;
}
}
}
h[location].flag = 1;
array_2[count] = h[location].num - disk_head;
if(array_2[count] < 0)
{
array_2[count] = disk_head - h[location].num;
}
disk_head = h[location].num;
}
count = 0;
for(count=0;count<limit;count++)
{
sum = sum + array_2[count];
}
printf("\nTotal movements of the cylinders:\t%d", sum);
return 0;
}