Skip to content
Snippets Groups Projects
Verified Commit 04ff3346 authored by orestis.malaspin's avatar orestis.malaspin
Browse files

added swap

parent 90e53aaa
No related branches found
No related tags found
No related merge requests found
Pipeline #14561 passed
...@@ -15,6 +15,12 @@ void find_min(double tab[], int i0, int *ind, double *min) { ...@@ -15,6 +15,12 @@ void find_min(double tab[], int i0, int *ind, double *min) {
} }
} }
void swap(double *a, double *b) {
double tmp = *a;
*a = *b;
*b = tmp;
}
int main() { int main() {
srand(time(NULL)); srand(time(NULL));
double tab[SIZE]; double tab[SIZE];
...@@ -26,9 +32,7 @@ int main() { ...@@ -26,9 +32,7 @@ int main() {
double min = tab[i]; double min = tab[i];
int ind_min = i; int ind_min = i;
find_min(tab, i, &ind_min, &min); find_min(tab, i, &ind_min, &min);
double tmp = tab[i]; swap(&tab[i], &tab[ind_min]);
tab[i] = min;
tab[ind_min] = tmp;
} }
for (int i = 0; i < SIZE; ++i) { for (int i = 0; i < SIZE; ++i) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment