-
Notifications
You must be signed in to change notification settings - Fork 1
/
circular.c
159 lines (95 loc) · 2.8 KB
/
circular.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//Author Conner Williams
#include <stdio.h>
#include <stdlib.h>
#include "blockalgorithms.h"
void circular(int *locationArray, int num){
const int NUM_LOCATIONS = num;
int startLocation = 0;
int largerArray[NUM_LOCATIONS];
int smallerArray[NUM_LOCATIONS];
int locations[NUM_LOCATIONS];
for(int i = 0; i < NUM_LOCATIONS; i++){
locations[i] = *locationArray;
locationArray++;
}
largerArray[0] = locations[0];
smallerArray[0] = 0;
createUpperArray(locations, largerArray, NUM_LOCATIONS);
createLowerArray(locations, smallerArray, largerArray, NUM_LOCATIONS);
//calculate total seek
int startingPosition = largerArray[0];
int seek = 0;
int totalSeek = 0;
for(int i = 0; i < NUM_LOCATIONS; i++){
if(largerArray[i] != 251){
seek = largerArray[i] - startingPosition;
totalSeek += seek;
startingPosition = largerArray[i];
}
}
for(int i = 0; i < NUM_LOCATIONS; i++){
if(smallerArray[i] != largerArray[0]){
seek = startingPosition - smallerArray[i];
if(seek < 0){
seek = seek * -1;
totalSeek += seek;
startingPosition = smallerArray[i];
}
else{
totalSeek += seek;
startingPosition = smallerArray[i];
}
}
}
printf("C-Look Total Seek: %d\n", totalSeek);
}
//Function to create upper array
void createUpperArray(int *locationArray, int *greaterThanArray, int num){
const int NUM_LOCATIONS = num;
int lowerLimit = greaterThanArray[0];
int upperLimit = 250;
locationArray[0] = -1;
for(int i = 1; i < NUM_LOCATIONS; i++){
int smallest = 251;
int smallestPosition = 0;
for(int i = 0; i < NUM_LOCATIONS; i++){
if(locationArray[i] >= lowerLimit && locationArray[i] <= upperLimit && locationArray[i] < smallest){
smallest = locationArray[i];
smallestPosition = i;
}
}
locationArray[smallestPosition] = -1;
greaterThanArray[i] = smallest;
lowerLimit = smallest;
}
}
//Function to create lower array
void createLowerArray(int *locationArray, int *lessThanArray, int *greaterThanArray, int num){
int NUM_LOCATIONS = num;
int lowerLimit = 0;
int upperLimit = greaterThanArray[0];
int smallest = locationArray[1];
int smallestPosition = 1;
for(int i = 1; i < NUM_LOCATIONS; i++){
if(locationArray[i] > -1 && locationArray[i] < smallest){
smallest = locationArray[i];
smallestPosition = i;
}
}
lowerLimit = smallest;
lessThanArray[0] = smallest;
locationArray[smallestPosition] = -1;
for(int i = 1; i < NUM_LOCATIONS; i++){
smallest = greaterThanArray[0];
smallestPosition = 0;
for(int j = 0; j < NUM_LOCATIONS; j++){
if(locationArray[j] > lowerLimit && locationArray[j] < upperLimit && locationArray[j] < smallest){
smallest = locationArray[j];
smallestPosition = j;
}
}
locationArray[smallestPosition] = -1;
lessThanArray[i] = smallest;
lowerLimit = smallest;
}
}