Skip to content

Instantly share code, notes, and snippets.

/helpers.c Secret

Created April 17, 2017 20:19
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 anonymous/eb3404b132d75f6c0b4ba34e1bd494c3 to your computer and use it in GitHub Desktop.
Save anonymous/eb3404b132d75f6c0b4ba34e1bd494c3 to your computer and use it in GitHub Desktop.
helpers.c - shared from CS50 IDE
/**
* helpers.c
*
* Helper functions for Problem Set 3.
*/
#include <cs50.h>
#include <stdio.h> //da togliere
#include "helpers.h"
/**
* Returns true if value is in array of n values, else false.
*/
bool search(int value, int values[], int n)
{
return false;
}
/**
* Sorts array of n values.
*/
void sort(int values[], int n)
{
int swapcounter = 1;
int temp;
while (swapcounter > 0) {
swapcounter = 0;
for (int i = 0; i<n-1; i++){
for (int j = 0; j<n-1; j++) {
if (values[i]>values[j+1]) {
temp = values[j+1];
values[j+1] = values[i];
values[i] = temp;
swapcounter++;
}
}
}
}
for (int i = 0; i < n; i++)
{
printf("value [%d] = %d\n", i, values[i]);
}
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment