int *helper = new int[r+1];
int i = r;
helper[i]=A[h];
i++;
The first iteration of this (with i == r
) is the first and the last that actually stays within boundaries of helper
. After that, you are cheerfully overrunning the buffer.
Only the last element of helper
(and a bunch of random memory past it) ever gets assigned to; the rest remains uninitialized.