Implementation (Part 1)
Lesson 5 of 9 in Coddy's Merge Sort - DSA Series course.
We will build Merge Sort from its core operation up.
Challenge
EasyThe heart of Merge Sort is combining two already sorted lists into one sorted list. Let's build that first.
Write a function named merge that takes two sorted integer arrays, left and right, and returns a single sorted array containing all their elements.
Walk both arrays at the same time: repeatedly take the smaller of the two front elements. When one array runs out, append everything left in the other.
Try it yourself
#include <stdlib.h>
int* merge(int* left, int left_size, int* right, int right_size, int* returnSize) {
// Write code here
*returnSize = 0;
return left;
}
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)