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,22 @@
a := [2,5,8,7,0,9,1,3,6,4];
qsort(a);
print(a);
proc qsort(rw a);
if #a > 1 then
pivot := a(#a div 2 + 1);
l := 1;
r := #a;
(while l < r)
(while a(l) < pivot) l +:= 1; end;
(while a(r) > pivot) r -:= 1; end;
swap(a(l), a(r));
end;
qsort(a(1..l-1));
qsort(a(r+1..#a));
end if;
end proc;
proc swap(rw x, rw y);
[y,x] := [x,y];
end proc;

View file

@ -0,0 +1,12 @@
a := [2,5,8,7,0,9,1,3,6,4];
print(qsort(a));
proc qsort(a);
if #a > 1 then
pivot := a(#a div 2 + 1);
a := qsort([x in a | x < pivot]) +
[x in a | x = pivot] +
qsort([x in a | x > pivot]);
end if;
return a;
end proc;