From 57d66ef6df8acd93f1fe00be9d9239a5f9969f30 Mon Sep 17 00:00:00 2001 From: Mahmud031 <36454130+Mahmud031@users.noreply.github.com> Date: Tue, 25 Jun 2019 05:02:26 +0300 Subject: [PATCH] Added merge-sort in MATLAB (#27783) * Added merge-sort in MATLAB * fix: changed c++ to cpp --- .../sorting-algorithms/merge-sort/index.md | 91 +++++++++++++++++-- 1 file changed, 81 insertions(+), 10 deletions(-) diff --git a/guide/english/algorithms/sorting-algorithms/merge-sort/index.md b/guide/english/algorithms/sorting-algorithms/merge-sort/index.md index d2b49c7336..48641fa308 100644 --- a/guide/english/algorithms/sorting-algorithms/merge-sort/index.md +++ b/guide/english/algorithms/sorting-algorithms/merge-sort/index.md @@ -8,7 +8,7 @@ Merge Sort is a USFCA * HackerEarth - -### Relavant videos on freeCodeCamp YouTube channel -* Merge Sort algorithm - MyCodeSchool - -### Other Resources: -* Wikipedia -* GeeksForGeeks -* Merge Sort - CS50 - ### Implementaion in JS ```js const list = [23, 4, 42, 15, 16, 8, 3] @@ -181,6 +172,32 @@ int main() ``` ### Implementation in C++ + +Let us consider array A = {2,5,7,8,9,12,13} +and array B = {3,5,6,9,15} and we want array C to be in ascending order as well. + +```cpp +void mergesort(int A[],int size_a,int B[],int size_b,int C[]) +{ + int token_a,token_b,token_c; + for(token_a=0, token_b=0, token_c=0; token_a left(k)) + k = k+1; + j = j+1; + end + sorted(j) = right(i); + sorted(j+1:(j+length(left(k:end)))) = left(k:end); + j = j+1; + end + end + +end + +``` + +### Relavant videos on freeCodeCamp YouTube channel +* Merge Sort algorithm - MyCodeSchool + +### Other Resources: +* Wikipedia +* GeeksForGeeks +* Merge Sort - CS50