Skip to content

Instantly share code, notes, and snippets.

@19h
Created February 23, 2012 02:10
Show Gist options
  • Save 19h/1889222 to your computer and use it in GitHub Desktop.
Save 19h/1889222 to your computer and use it in GitHub Desktop.
bla
a = [123, 345, 657, 234, 534, 567867, 234, 123, -132, -799, -243, 543, 234, 5768, 5234, 678, 1, 345, 2, 7, 9, -4, 3456, 324];
// Das unsortierte Array
var print = print || console.log;
var b = a.length, // Die Länge
c = a, // Eine Kopie des Arrays..
d, e, f, g, h; // bla, bla.
d = (b >> 1) + 1; // b/2 + 1! // Die Hälfte plus eins!
for (f = b;;) {
if (1 < d) h = c[--d];
else if (h = c[f], c[f] = c[1], 1 == --f) {
c[1] = h;
break
}
g = d;
0
for (e = d << 1; e <= f;)
e < f && c[e] < c[e + 1] && ++e, h < c[e]
?
(
c[g] = c[e],
e += g = e
)
: e = f + 1;
c[g] = h
}
print(a.slice(1, a.length).filter(function (i) { // remove the undefined!
return void 0 !== i
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment