all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
|
|
@ -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]));
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue