-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscan2.c
61 lines (51 loc) · 1.36 KB
/
scan2.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
#include <stdio.h>
void main()
{
int maxrange, numtracks, head;
printf("Enter the number of tracks: ");
scanf("%d", &numtracks);
int tracks[numtracks + 2];
int q[numtracks];
printf("Enter the maxrange of the tracks: ");
scanf("%d", &maxrange);
printf("Enter the head: ");
scanf("%d", &head);
for (int i = 0; i < numtracks; i++)
{
printf("Enter the track to be traversed: ");
scanf("%d", &q[i]);
tracks[i] = q[i];
}
tracks[numtracks] = head;
tracks[numtracks + 1] = maxrange;
for (int i = 0; i < numtracks + 2; i++)
{
for (int j = 0; j < (numtracks + 2) - i - 1; j++)
{
if (tracks[j] > tracks[j + 1])
{
int temp = tracks[j];
tracks[j] = tracks[j + 1];
tracks[j + 1] = temp;
}
}
}
int headpos;
for (int i = 0; i < numtracks + 2; i++)
{
if (tracks[i] == head)
{
headpos = i;
}
}
for (int i = headpos; i < numtracks + 2; i++)
{
printf("%d => ", tracks[i]);
}
for (int i = headpos - 1; i >= 0; i--)
{
printf("%d => ", tracks[i]);
}
int tskt = (maxrange - head) + (maxrange - tracks[0]);
printf("total seek time: %d", tskt);
}