Skip to content

Instantly share code, notes, and snippets.

@CraigRodrigues
Created June 8, 2016 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CraigRodrigues/a12ed324546a89e5cb517ca9ebe64bb3 to your computer and use it in GitHub Desktop.
Save CraigRodrigues/a12ed324546a89e5cb517ca9ebe64bb3 to your computer and use it in GitHub Desktop.
CS50 pset3 - "Game of Fifteen" - Linear Search Algorithm
/**
* 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