Created
May 5, 2017 02:41
-
-
Save ZaneWithSpoon/b9ab17aa627a43136d4952687d44f8f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ============================================================================ | |
Name : part1.c | |
Authors : Zane Witherspoon & Tim Siwula | |
Version : 3.14 | |
Description : takes in an int between 0-4999 as only argument | |
============================================================================ */ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
int get_rand(); | |
int sort_list(int starting_address, int a[]); | |
int FCFS(int start, int a[]); | |
int SSTF(int start_index, int a[]); | |
int SCAN(int start_index, int a[]); | |
int CSCAN(int start_index, int a[]); | |
int LOOK(int start_index, int a[]); | |
int CLOOK(int start_index, int a[]); | |
int addresses[1000]; | |
int sorted_addresses[1001]; | |
int starting_address; | |
int main( int argc, char *argv[] ) { | |
srand(time(NULL)); | |
starting_address = atoi(argv[1]); | |
for (int i = 0; i < 1000; ++i) { | |
addresses[i] = get_rand(); | |
printf("%d\n", addresses[i]); | |
} | |
int start_index = sort_list(starting_address, addresses); | |
//the alrogithms | |
int fcfs_count = FCFS(starting_address, addresses); | |
printf("FCFS distance traveled %d\n", fcfs_count); | |
int sstf_count = SSTF(start_index, sorted_addresses); | |
//printf("SSTF distance traveled %d\n", fcfs_count); | |
} | |
//takes in addresses, returns total distance traveled | |
int FCFS(int start, int a[]) { | |
int distance = 0; | |
int current = start; | |
for (int i = 0; i < 1000; ++i) { | |
if ((a[i] - current) > 0) { | |
distance += (a[i] - current); | |
} else { | |
distance += (current - a[i]); | |
} | |
current = a[i]; | |
} | |
return distance; | |
} | |
int SSTF(int start_index, int a[]) { | |
int read[1000]; | |
for (int i = 0; i < 1000; ++i) | |
{ | |
read[i] = 0; | |
} | |
return 0; | |
} | |
int SCAN(int start_index, int a[]) { | |
return 0; | |
} | |
//returns the index of the starting vlue | |
int sort_list(int start, int a[]) { | |
for (int i = 0; i < 1000; ++i) | |
{ | |
sorted_addresses[i] = a[i]; | |
} | |
sorted_addresses[1000] = start; | |
int array_size = 1001; | |
int i, j, temp; | |
for (i = 0; i < (array_size - 1); ++i) | |
{ | |
for (j = 0; j < array_size - 1 - i; ++j ) | |
{ | |
if (sorted_addresses[j] > sorted_addresses[j+1]) | |
{ | |
temp = sorted_addresses[j+1]; | |
sorted_addresses[j+1] = sorted_addresses[j]; | |
sorted_addresses[j] = temp; | |
} | |
} | |
} | |
for (int i = 0; i < 1001; ++i) | |
{ | |
if (sorted_addresses[i] == start) | |
return i; | |
} | |
return 0; | |
} | |
int get_rand() { | |
return (rand() % 5000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment