Your problem is with the following line:
values = result;
You can not assign every value from one array into another with a simple one-line statementassignment like this. In order to change the array 'haystack', the sorted values needsfrom your result
array need to be put back into the values
array. I believe the best wayYou would probably need to do this is withuse another for
loop.
As an aside, you could also simplify this code, removing the cumulative counting, getting rid of the result
array altogether and just assigning the sorted values straight back into values
.