You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
867 B
40 lines
867 B
const Sorter = {
|
|
sort: function(chords, start, end, getVal, swap) {
|
|
if (end <= start) {
|
|
return chords;
|
|
}
|
|
|
|
var left = start;
|
|
var right = end;
|
|
|
|
var pivot = Math.floor((right + left) / 2);
|
|
var pivotval = getVal(pivot);
|
|
var tmp;
|
|
var rval;
|
|
|
|
while (left <= right) {
|
|
while (getVal(left) < pivotval) {
|
|
left++;
|
|
}
|
|
|
|
while (getVal(right) > pivotval) {
|
|
right--;
|
|
}
|
|
|
|
if (left <= right) {
|
|
chords = swap(chords, left, right);
|
|
|
|
left++;
|
|
right--;
|
|
}
|
|
break;
|
|
}
|
|
|
|
Sorter.sort(chords, start, right, getVal, swap);
|
|
Sorter.sort(chords, left, end, getVal, swap);
|
|
|
|
return chords;
|
|
}
|
|
};
|
|
|
|
export default Sorter;
|
|
|