-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclook.c
More file actions
76 lines (75 loc) · 1.33 KB
/
clook.c
File metadata and controls
76 lines (75 loc) · 1.33 KB
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
75
76
#include<stdio.h>
#include<stdlib.h>
int main()
{
int RQ[100], i, j, n, TotalHeadMoment = 0, initial, size, move, index;
printf("Enter the number of requests: ");
scanf("%d", &n);
printf("Enter the request sequence: ");
for(i = 0; i < n; i++) {
scanf("%d", &RQ[i]);
}
printf("Enter the initial head position: ");
scanf("%d", &initial);
printf("Enter the total disk size: ");
scanf("%d", &size);
printf("Enter the head movement direction 1 for high, 0 for low: ");
scanf("%d", &move);
for(i = 0; i < n; i++)
{
for(j = 0; j < n - i - 1; j++)
{
if(RQ[j] > RQ[j+1])
{
int temp = RQ[j];
RQ[j] = RQ[j+1];
RQ[j+1] = temp;
}
}
}
for(i = 0; i < n; i++)
{
if(initial < RQ[i])
{
index = i;
break;
}
}
if(move == 1)
{
for(i = index; i < n; i++)
{
TotalHeadMoment += abs(RQ[i] - initial);
initial = RQ[i];
}
//change
/*TotalHeadMoment += abs(size - RQ[i-1]-1);
TotalHeadMoment += abs(size - 1-0);
initial =0;*/
for(i =0;i < index ; i++)
{
TotalHeadMoment += abs(RQ[i] - initial);
initial = RQ[i];
}
}
else
{
for(i = index - 1; i >= 0; i--)
{
TotalHeadMoment += abs(RQ[i] - initial);
initial = RQ[i];
}
//change
/*
TotalHeadMoment += abs( RQ[i+1]-0);
TotalHeadMoment += abs( size-1-0);
initial = size-1;*/
for(i = n-1; i >=index; i--)
{
TotalHeadMoment += abs(RQ[i] - initial);
initial = RQ[i];
}
}
printf("Total head movement is: %d\n", TotalHeadMoment);
return 0;
}