Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- procedure Sort(var arr: tarr; n: integer);
- var
- i, j, k, min, max, range, bindex, temp: integer;
- buckets: tm;
- begin
- min := arr[0];
- max := arr[0];
- for I := 1 to High(arr) do
- begin
- if arr[i] > max then
- max := arr[i];
- if arr[i] < min then
- min := arr[i];
- end;
- range := (max - min) div n;
- setlength(buckets, n, range);
- for I := 0 to high(arr) do
- begin
- bindex := (arr[i] - min) div range;
- j := 0;
- while (j < range) and (buckets[bindex][j] <> 0) do
- inc(j);
- buckets[bindex][j] := arr[i];
- end;
- for i := 0 to high(buckets) do
- begin
- for j := 1 to length(buckets) do
- begin
- for k := 1 to length(buckets) do
- if buckets[i][j] < buckets[i][j - 1] then
- begin
- temp := buckets[i][j];
- buckets[i][j] := buckets[i][j - 1];
- buckets[i][j - 1] := temp;
- end;
- end;
- end;
- k := 0;
- for I := 0 to high(buckets) do
- for j := 0 to length(buckets) do
- begin
- arr[k] := buckets[i][j];
- writeln(arr[k]);
- inc(k);
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement