I am new to C++, and am writing a merge sort program. However, every time I run it, the array is printed out for the second time, but unsorted. I think somehow that it isn't being returned. I am an early intermediate of java, and a similar program to this works fine, leading me to think that it's a syntactical error, not a logic error. Here's the code:
arr = merge(left, right, leftLength, rightLength); That will do nothing. You passed the pointer by value, but if you do it by reference it will throw a compiler error (because an array is a const pointer).
1 2 3 4 5 6 7
int array[10];
//this is what your function is doing
int *ptr = array;
ptr = some_place_with_sorted_data; //it does not affect array
//this is illegal
array = some_place_with_sorted_data;