I will never ever forget merge sort again
i learned merge\'s sort from : https://www.youtube.com/watch?v=mB5HXBb_HY8\ncopy paste on youtube if link doesn\'t works\nhe explained really well , i really ap
i learned merge\'s sort from : https://www.youtube.com/watch?v=mB5HXBb_HY8\ncopy paste on youtube if link doesn\'t works\n**he explained really well** , i really appreciate his beirf explanation, watch this and then **come back here if you were not able to code**.\n\n**assuming you still needs help in coding part ( yeah I too needed ), here is the implementation**\n```\nvoid merge(vector<int> &a , int l , int mid , int h)     // make sure you passed be reference else changes wont reflect \n    {\n        vector<int> x(a.begin()+l, a.begin()+mid+1);         // making temp array for 1st segment \n        vector<int> y(a.begin()+mid+1, a.begin()+h+1);  // making temp array for  2nd segment\n        \n        int n = x.size();\n        int m = y.size();\n        int i,j,k;  i=j=0;  k=l;\n        \n        while(i<n and j<m)                                  // standard merging algo as explained in video\n            a[k++] = (x[i]<y[j]) ? x[i++] : y[j++];\n        while(i<n)\n            a[k++] = x[i++];\n        while(j<m)\n            a[k++] = y[j++];         \n\t}        \n    void mergeSort(vector<int> &a , int l , int h)     // this function recursively calls itself until segment is greater than 1 length\n    {\n        if(l<h)\n        {\n            int mid = l+(h-l)/2;\n            mergeSort(a,l,mid);\n            mergeSort(a,mid+1,h);\n            merge(a,l,mid,h);\n        }\n    }    \n    vector<int> sortArray(vector<int>& nums) {        \n        int n = nums.size();\n        mergeSort(nums,0,n-1);\n        return nums;\n    }\n```\nThanks for reading, please upvote if this was helpful
['Recursion', 'Sorting', 'Merge Sort', 'C++']