Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,12 @@
|
|||
import std.stdio : writefln, writeln;
|
||||
import std.algorithm: filter;
|
||||
import std.array;
|
||||
|
||||
T[] quickSort(T)(T[] xs) =>
|
||||
xs.length == 0 ? [] :
|
||||
xs[1 .. $].filter!(x => x< xs[0]).array.quickSort ~
|
||||
xs[0 .. 1] ~
|
||||
xs[1 .. $].filter!(x => x>=xs[0]).array.quickSort;
|
||||
|
||||
void main() =>
|
||||
[4, 65, 2, -31, 0, 99, 2, 83, 782, 1].quickSort.writeln;
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
import std.stdio, std.array;
|
||||
|
||||
T[] quickSort(T)(T[] items) pure nothrow {
|
||||
if (items.empty)
|
||||
return items;
|
||||
T[] less, notLess;
|
||||
foreach (x; items[1 .. $])
|
||||
(x < items[0] ? less : notLess) ~= x;
|
||||
return less.quickSort ~ items[0] ~ notLess.quickSort;
|
||||
}
|
||||
|
||||
void main() {
|
||||
[4, 65, 2, -31, 0, 99, 2, 83, 782, 1].quickSort.writeln;
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
import std.stdio, std.algorithm;
|
||||
|
||||
void quickSort(T)(T[] items) pure nothrow @safe @nogc {
|
||||
if (items.length >= 2) {
|
||||
auto parts = partition3(items, items[$ / 2]);
|
||||
parts[0].quickSort;
|
||||
parts[2].quickSort;
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
auto items = [4, 65, 2, -31, 0, 99, 2, 83, 782, 1];
|
||||
items.quickSort;
|
||||
items.writeln;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue