All pastes #106642 Raw Edit

Mine

public text v1 · immutable
#106642 ·published 2006-07-30 12:22 UTC
rendered paste body
Function LinearSort(s: string): string;
var charcount: array[#0..#255] of integer;
    i: integer;
    j: char;
begin
  // zero the charcount array
  fillchar(charcount, sizeof(charcount), 0);

  // count the particular characters in s
  for i:=1 to Length(s) do
    inc(charcount[s[i]]);

  // the result string is the same length as the input
  SetLength(Result, Length(s));
  // i = the current length of the result string + 1
  i:=1;

  // build the result string
  for j:=#0 to #255 do
  begin
    fillchar(Result[i], charcount[j], j);
    inc(i, charcount[j]);
  end;
end;