I am trying to implement the Merge Sort algorithm. I am following the algorithm mentioned in the CLRS book.Here is my code
#include #include
The problem is very simple: your last loop in the merge(...) has a problem.
loop
merge(...)
Move the l = 0 and m = 0 before the loop starts, because you are using the values 0 and 1 for l and m always, in each loop iteration.
l = 0
m = 0
Change it to:
int l=0, m=0; for(i=0;i<=end_index;i++){ if(sub_arr1[l]