Program Algorithm; { This method was actually (re)invented by myself, but, inevitably, it must have been known for a while as: Adress calculation sorting. Described on page 99 of "The Art of Computer Programming" volume 3 / "Sorting and Searching" by Donald E. Knuth } const LIM1 = 200; LIM2 = 700; var rij : array[1..LIM1] of word; klad : array[1..LIM2] of word; n : word; procedure MemSort; { Method: { map number -> memory location } var p, q, r : word; begin for q := 1 to LIM2 do klad[q] := 0; for p := 1 to LIM1 do begin q := rij[p]; klad[q] := klad[q] + 1; end; { Want to see the mapping: } { for q := 1 to LIM2 do Write(klad[q],' '); Writeln; } p := 0; for q := 1 to LIM2 do begin if klad[q] = 0 then Continue; for r := 1 to klad[q] do begin p := p + 1; rij[p] := q; end; end; end; begin { Works well for small numbers which are close together: } for n := 1 to LIM1 do rij[n] := Random(LIM2)+1; for n := 1 to LIM1 do Write(rij[n],' '); Writeln; MemSort; for n := 1 to LIM1 do Write(rij[n],' '); Writeln; end.