Merge branch 'changeorder' of UBB/sort into master

This commit is contained in:
Chris Cromer 2018-11-17 17:12:04 -03:00 committed by Gitea
commit 674e919cc0
2 changed files with 21 additions and 12 deletions

View File

@ -325,36 +325,42 @@ int main (int argc, char **argv) {
} }
} }
if (merge) { // O(nlog(n))
start_sort("Merge sort corriendo... ", n);
merge_sort(work_array, n);
end_sort();
}
if (quick) { if (quick) {
start_sort("Quick sort corriendo... ", n); start_sort("Quick sort corriendo... ", n);
quick_sort(work_array, n); quick_sort(work_array, n);
end_sort(); end_sort();
} }
if (bubble) { // O(nlog(n))
start_sort("Bubble sort corriendo... ", n); if (merge) {
bubble_sort(work_array, n); start_sort("Merge sort corriendo... ", n);
merge_sort(work_array, n);
end_sort(); end_sort();
} }
// O(nlog2(n))
if (bitonic) { if (bitonic) {
start_sort("Bitonic sort corriendo... ", n); start_sort("Bitonic sort corriendo... ", n);
bitonic_sort(work_array, n); bitonic_sort(work_array, n);
end_sort(); end_sort();
} }
// O(n+k)
if (count) { if (count) {
start_sort("Count sort corriendo... ", n); start_sort("Count sort corriendo... ", n);
count_sort(work_array, n); count_sort(work_array, n);
end_sort(); end_sort();
} }
// O(n^2)
if (bubble) {
start_sort("Bubble sort corriendo... ", n);
bubble_sort(work_array, n);
end_sort();
}
// O(n^2)
if (selection) { if (selection) {
start_sort("Selection sort corriendo... ", n); start_sort("Selection sort corriendo... ", n);
selection_sort(work_array, n); selection_sort(work_array, n);

View File

@ -19,7 +19,10 @@
* @param yp Segundo valor * @param yp Segundo valor
*/ */
void swap(int *xp, int *yp) { void swap(int *xp, int *yp) {
int temp = *xp; if (xp == yp) {
*xp = *yp; return;
*yp = temp; }
*xp = *xp + *yp;
*yp = *xp - *yp;
*xp = *xp - *yp;
} }