Skip to content

Instantly share code, notes, and snippets.

@renatoargh
Created July 23, 2012 18:57
Show Gist options
  • Save renatoargh/3165423 to your computer and use it in GitHub Desktop.
Save renatoargh/3165423 to your computer and use it in GitHub Desktop.
function merge(array, lower, half, upper){
var left = [], i = 0;
while (i < half - lower + 1){
left.push(array[lower + i++]);
}
left.push(Number.MAX_VALUE);
var right = [], j = 0;
while(j < upper - half){
right.push(array[half + j++ + 1]);
}
right.push(Number.MAX_VALUE);
i = j = 0;
for(k = lower; k <= upper; k++){
array[k] = left[i] < right[j] ? left[i++] : right[j++];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment