Created
January 26, 2020 01:03
-
-
Save BrooklinJazz/126325ac7defd686aec639855099eadd to your computer and use it in GitHub Desktop.
a documented example of merge sort in c
This file contains hidden or 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
| void mergeSort(int arr[], int leftIndex, int rightIndex) | |
| { | |
| // 1. If the array has < 1 element do nothing. otherwise: | |
| if (leftIndex < rightIndex) | |
| { | |
| // 2. determine the middle index of the array | |
| int midIndex = leftIndex + ((rightIndex - leftIndex) / 2); | |
| // 3. mergeSort the left half of the array | |
| mergeSort(arr, leftIndex, midIndex); | |
| // 4. mergeSort the left half of the array | |
| mergeSort(arr, midIndex + 1, rightIndex); | |
| // 5. now that the left half and right half of the array are sorted, merge them. | |
| merge(arr, leftIndex, midIndex, rightIndex); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment