Advertisement
ksyshshot

мусор

Nov 21st, 2022
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.25 KB | Source Code | 0 0
  1. procedure Sort(var arr: tarr; n: integer);
  2. var
  3.     i, j, k, min, max, range, bindex, temp: integer;
  4.     buckets: tm;
  5.  
  6. begin
  7.     min := arr[0];
  8.     max := arr[0];
  9.     for I := 1 to High(arr) do
  10.     begin
  11.         if arr[i] > max then
  12.             max := arr[i];
  13.         if arr[i] < min then
  14.             min := arr[i];
  15.     end;
  16.     range := (max - min) div n;
  17.     setlength(buckets, n, range);
  18.     for I := 0 to high(arr) do
  19.     begin
  20.         bindex := (arr[i] - min) div range;
  21.         j := 0;
  22.         while (j < range) and (buckets[bindex][j] <> 0) do
  23.             inc(j);
  24.         buckets[bindex][j] := arr[i];
  25.     end;
  26.     for i := 0 to high(buckets) do
  27.     begin
  28.         for j := 1 to length(buckets) do
  29.         begin
  30.             for k := 1 to length(buckets) do
  31.                 if buckets[i][j] < buckets[i][j - 1] then
  32.                 begin
  33.                     temp := buckets[i][j];
  34.                     buckets[i][j] := buckets[i][j - 1];
  35.                     buckets[i][j - 1] := temp;
  36.                 end;
  37.         end;
  38.     end;
  39.     k := 0;
  40.     for I := 0 to high(buckets) do
  41.         for j := 0 to length(buckets) do
  42.         begin
  43.            arr[k] := buckets[i][j];
  44.            writeln(arr[k]);
  45.            inc(k);
  46.         end;
  47. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement