Skip to content

Instantly share code, notes, and snippets.

@thgreasi
Last active December 27, 2015 08:09
Show Gist options
  • Save thgreasi/7293898 to your computer and use it in GitHub Desktop.
Save thgreasi/7293898 to your computer and use it in GitHub Desktop.
superFastSort.js
function superFastSort ( t , start, len ) {
"use strict";
if (start === undefined) {
start = 0;
}
if (len === undefined) {
len = t.length - start;
}
if (len > 1) {
var left = start;
var right = start + len - 1;
var base = t[right];
while (left <= right) {
while (t[left] < base) {
left++;
}
while (t[right] > base) {
right--;
}
if (left <= right) {
// swap
var tmp = t[left];
t[left] = t[right];
t[right] = tmp;
left++;
right--;
}
}
superFastSort(t, start, right + 1 - start);
superFastSort(t, right + 1, len - right - 1);
}
}
// var table = [17, 12, 6, 19, 23, 8, 5, 10];
// superFastSort(table);
// console.log(table);
@sebald
Copy link

sebald commented May 8, 2014

Is there a version that works with negative numbers?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment