Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,39 @@
|
|||
function sort(array, less) {
|
||||
|
||||
function swap(i, j) {
|
||||
var t = array[i];
|
||||
array[i] = array[j];
|
||||
array[j] = t;
|
||||
}
|
||||
|
||||
function quicksort(left, right) {
|
||||
|
||||
if (left < right) {
|
||||
var pivot = array[left + Math.floor((right - left) / 2)],
|
||||
left_new = left,
|
||||
right_new = right;
|
||||
|
||||
do {
|
||||
while (less(array[left_new], pivot)) {
|
||||
left_new += 1;
|
||||
}
|
||||
while (less(pivot, array[right_new])) {
|
||||
right_new -= 1;
|
||||
}
|
||||
if (left_new <= right_new) {
|
||||
swap(left_new, right_new);
|
||||
left_new += 1;
|
||||
right_new -= 1;
|
||||
}
|
||||
} while (left_new <= right_new);
|
||||
|
||||
quicksort(left, right_new);
|
||||
quicksort(left_new, right);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
quicksort(0, array.length - 1);
|
||||
|
||||
return array;
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
var test_array = [10, 3, 11, 15, 19, 1];
|
||||
var sorted_array = sort(test_array, function(a,b) { return a<b; });
|
||||
|
|
@ -0,0 +1 @@
|
|||
[ 1, 3, 10, 11, 15, 19 ]
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
const qsort = ([pivot, ...others]) =>
|
||||
pivot === void 0 ? [] : [
|
||||
...qsort(others.filter(n => n < pivot)),
|
||||
pivot,
|
||||
...qsort(others.filter(n => n >= pivot))
|
||||
];
|
||||
|
||||
qsort( [ 11.8, 14.1, 21.3, 8.5, 16.7, 5.7 ] )
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
function qsort( xs ){
|
||||
return xs.length === 0 ? [] : [].concat(
|
||||
qsort( xs.slice(1).filter(function(x){ return x< xs[0] })),
|
||||
xs[0],
|
||||
qsort( xs.slice(1).filter(function(x){ return x>= xs[0] }))
|
||||
)
|
||||
}
|
||||
qsort( [ 11.8, 14.1, 21.3, 8.5, 16.7, 5.7 ] )
|
||||
Loading…
Add table
Add a link
Reference in a new issue