This is the code I've done for the merge function of my merge sort algorithm.
When called the function successfully merges the two arrays passed in however it does not sort them. I can not figure out why this happens. If I output the result array it is just the right array and then the left array. I thought the comparisons made in the for loop should have put them in order from smallest to largest. Any help is appreciate thanks.
The code is (more or less) correct if you're feeding it two already sorted arrays. I say more or less because the code will fail if numr > numl. It may be that is always true. Obviously we can't know from this snippet of code.
Changing the size allocated by new to newint[numl+numr] would be less fragile.
This function won't do anything useful, though, if fed arrays that are not already sorted.
Yeah, the problem is that it is supposed to sort it as well, not just combine it. I though that in my if statements comparing left and right values and putting them into the solution I was sorting them but this is clearly not the case.