-
-
Save anonymous/ae432b578f3dae049c98 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
bool search(int value, int values[], int n) | |
{ | |
int lower = 0; | |
int upper = n; | |
int middle; | |
printf ("start search"); | |
do | |
{ | |
middle = (lower + upper) / 2; | |
if (values [middle] == value) | |
{ | |
return true; | |
break; | |
} | |
if (values [middle] < value) | |
lower = middle + 1; | |
else | |
upper = middle - 1; | |
} | |
while (middle != upper); | |
return false; | |
} | |
/** | |
* Sorts array of n values. | |
*/ | |
void sort(int values[], int n) | |
{ | |
int counter = 0; | |
int swap = 0; | |
do | |
{ | |
swap = 0; | |
for (int i = 0; i < n - 1 - counter; i++) | |
{ | |
int temp; | |
for (int j = 0; j < n; j++) | |
printf ("%d ", values [j]); | |
// compare values | |
if (values[i] > values[i + 1]) | |
{ | |
swap = 1; | |
temp = values [i]; | |
values[i] = values[i + 1]; | |
values[i + 1] = temp; | |
} | |
} | |
counter ++; | |
} | |
while (swap != 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment