Skip to content

Instantly share code, notes, and snippets.

@BrooklinJazz
Created January 26, 2020 01:03
Show Gist options
  • Select an option

  • Save BrooklinJazz/126325ac7defd686aec639855099eadd to your computer and use it in GitHub Desktop.

Select an option

Save BrooklinJazz/126325ac7defd686aec639855099eadd to your computer and use it in GitHub Desktop.
a documented example of merge sort in c
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