Sorting By PSP
Sorting is even easier than mode
Compute the position in the output by counting the number of elements smaller
begin
ST:= <## [Index2,Index1] S;
-- Construct Transpose of S
P := +<<[1..n,1..n](>>[1,1..n]S <= >>[1..n,1]ST);
-- Compare n^2 items, reduce
S := <##[Index1,P] S;
-- Reorder input using perm
end;
Cost is 2 permutes, 2 floods, partial reduction
Requires n^2 comparisons, though O(n log n) suffices; no early exit