Implementation (Part 2)
Lesson 6 of 9 in Coddy's Merge Sort - DSA Series course.
Now we combine splitting and merging into the full algorithm.
Challenge
EasyNow put it all together into the full algorithm.
Write a function named mergeSort that takes an integer array and returns it sorted in ascending order.
Split the array into two halves, sort each half by calling mergeSort on it (recursion), then merge the two sorted halves back together. An array with 0 or 1 elements is already sorted, so return it as is.
You can reuse the merge logic from the previous lesson.
Try it yourself
#include <stdlib.h>
int* mergeSort(int* arr, int arr_size, int* returnSize) {
// Write code here
*returnSize = arr_size;
return arr;
}
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Merge Sort - DSA Series
2The Algorithm
How it works?Pseudo CodeImplementation (Part 1)Implementation (Part 2)