Where is this variable values
initialized?:
values[k] = left[i];
EDIT (March 28, 2021):
Perhaps it is a global variable that is being used within the function, which means that the function is not self-contained. Consequently, we need to have the entire surrounding context of the function available to us in order to reproduce whatever problems you are having.