-
-
Save anonymous/eb3404b132d75f6c0b4ba34e1bd494c3 to your computer and use it in GitHub Desktop.
helpers.c - shared from CS50 IDE
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 | |
* | |
* 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