Created
June 8, 2016 19:09
-
-
Save CraigRodrigues/a12ed324546a89e5cb517ca9ebe64bb3 to your computer and use it in GitHub Desktop.
CS50 pset3 - "Game of Fifteen" - Linear Search Algorithm
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
/** | |
* helpers.c | |
* | |
* Computer Science 50 | |
* Problem Set 3 | |
* | |
* Helper functions for Problem Set 3. | |
*/ | |
#include <cs50.h> | |
#include "helpers.h" | |
/** | |
* Returns true if value is in array of n values, else false. | |
* | |
* Re-write search in such a way that it uses linear search, | |
* returning true if value is in values and false if value is not in values. | |
* Take care to return false right away if n isn’t even positive. | |
*/ | |
bool search(int value, int values[], int n) | |
{ | |
// linear search algorithm | |
for (int i = 0; i < n; i++) | |
{ | |
if (values[i] == value) | |
return true; | |
} | |
return false; | |
} | |
/** | |
* Sorts array of n values. | |
*/ | |
void sort(int values[], int n) | |
{ | |
// TODO: implement an O(n^2) sorting algorithm | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment