Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Implement Merge Sort using recursion.
vector<int> merge_sort(vector<int> nums) {
int length = nums.size();
if (length <= 1) {
return numbers;
int half = length/2;
vector<int> left_half = vector<int>(nums.begin(), nums.begin()+half);
vector<int> right_half = vector<int>(nums.begin()+half, nums.end());
vector<int> sorted_left = merge_sort(left_half);
vector<int> sorted_right = merge_sort(right_half);
vector<int> sorted_full = merge(sorted_left, sorted_right);
return sorted_full;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.