Conversation
|
|
||
| int temp[SIZE] = {0}; | ||
|
|
||
| void merge (int array[], int start_1, int end_1, int start_2, int end_2) |
There was a problem hiding this comment.
Personally I'd opt for two arrays, instead of start_1, start_2, end_1, end_2. Something along the lines of
void merge (int left[], int leftSz, int right[] int rightSz)
|
|
||
| void sort (int array[], int start, int end) | ||
| { | ||
| if (end > start) |
There was a problem hiding this comment.
if (end > start + 1) should be fine, one element is sorted by definition (though in reality this just means n extra steps, not too big a problem).
|
|
||
| #define SIZE 8 | ||
|
|
||
| int temp[SIZE] = {0}; |
There was a problem hiding this comment.
I'm not sure a global array is the best idea, especially since this is going to be constant size. What you probably want is a local temporary array/arrays within merge function.
| if (array[start_1] > array[start_2]) | ||
| { | ||
| // append smaller to array | ||
| temp[i] = array[start_2]; |
There was a problem hiding this comment.
temp is, in theory, a pointer to a global array with one int element. Make the size of the original array in main larger and something will break.
You're probably looking for something along the line of
int temp[end_2 - start_1 + 1];
Reviewing.