-
Notifications
You must be signed in to change notification settings - Fork 1
/
nonCircular.c
66 lines (45 loc) · 1.28 KB
/
nonCircular.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
//Author: Connor Paulson
#include <stdio.h>
#include <stdlib.h>
#include "blockalgorithms.h"
void nonCircular(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 = NUM_LOCATIONS - 1; i >= 0; 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("Look Total Seek: %d\n", totalSeek);
}