all tasks

This commit is contained in:
Ingy döt Net 2013-04-11 01:07:29 -07:00
parent b83f433714
commit 68f8f3e56b
14735 changed files with 178959 additions and 0 deletions

View file

@ -0,0 +1,14 @@
import std.stdio;
T[] quickSort(T)(T[] items) {
if (items.length <= 1)
return items;
T[] less, more;
foreach (x; items[1 .. $])
(x < items[0] ? less : more) ~= x;
return quickSort(less) ~ items[0] ~ quickSort(more);
}
void main() {
writeln(quickSort([4, 65, 2, -31, 0, 99, 2, 83, 782, 1]));
}

View file

@ -0,0 +1,18 @@
import std.stdio;
import std.algorithm;
void quickSort(T)(T[] items)
{
if (items.length >= 2) {
auto parts = partition3(items, items[$ / 2]);
quickSort(parts[0]);
quickSort(parts[2]);
}
}
void main()
{
auto items = [4, 65, 2, -31, 0, 99, 2, 83, 782, 1];
quickSort(items);
writeln(items);
}