Data update

This commit is contained in:
Ingy döt Net 2024-10-16 18:07:41 -07:00
parent 81fd053722
commit 52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions

View file

@ -0,0 +1,33 @@
type
colors = (red, white, blue);
procedure threeWayPartition(a: array of colors; mid: colors);
begin
var (i, j) := (0, 0);
var k := a.High;
while j <= k do
if a[j] < mid then
begin
swap(a[i], a[j]);
i += 1;
j += 1;
end
else if a[j] > mid then
begin
swap(a[j], a[k]);
k -= 1;
end
else j += 1;
end;
begin
var balls: array of colors;
repeat
balls := ArrGen(10, i -> |red, white, blue|.randomelement);
until balls <> balls.Sorted;
println('Original ball order:', balls);
threewaypartition(balls, white);
println('Sorted ball order: ', balls);
assert(balls <> balls.sorted, 'Not sorted!');
end.