Created
July 2, 2010 04:43
-
-
Save CarterA/460940 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
// Mergesort functions | |
void cz_merge(uint32_t *left, uint32_t *right, uint32_t *array, int length) { | |
for (int li = 0; li < (length / 2); li++) { | |
array[li] = left[li]; | |
} | |
for (int ri = 0; ri < ((length - 1) / 2 + 1); ri++) { | |
array[(length / 2) + ri] = right[ri]; | |
} | |
} | |
void cz_mergesort(uint32_t *array, int length) { | |
if (length <= 1) return; | |
uint32_t left[length / 2]; | |
uint32_t right[((length - 1) / 2 + 1)]; | |
for (int li = 0; li < (length / 2); li++) { | |
left[li] = array[li]; | |
} | |
for (int ri = 0; ri < ((length - 1) / 2 + 1); ri++) { | |
right[ri] = array[((length - 1) / 2 + 1) + ri]; | |
} | |
cz_mergesort(left, (length / 2)); | |
cz_mergesort(right, ((length - 1) / 2 + 1)); | |
cz_merge(left, right, array, length); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment