Your problem is with the following line:
values = result;
You can not assign every value from one array into another with a one-line statement like this. In order to change the array 'haystack', the sorted values needs to be put back into the values
array. I believe the best way to do this is with another for
loop.