blob: 6e9cc220d27b2d1fc7cce2e7a7d7b7bbb6849705 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
package body Shell is
-- sequence from Marcin Ciura, 2001
Gaps : array (Positive range 1 .. 8) of Integer := (701, 301, 132, 57, 23, 10, 4, 1);
procedure Sort(Arr : in out Array_T) is
Temp : Element_T;
Place : Integer;
begin
if Arr'Length <= 1 then
return;
end if;
for G of Gaps loop
for I in Integer range (Index_T'Pos(Arr'First) + G) .. Index_T'Pos(Arr'Last) loop
Place := I;
Temp := Arr(Index_T'Val(Place));
while Place >= (Index_T'Pos(Arr'First) + G) and then Arr(Index_T'Val(Place - G)) > Temp loop
Arr(Index_T'Val(Place)) := Arr(Index_T'Val(Place - G));
Place := Place - G;
end loop;
Arr(Index_T'Val(Place)) := Temp;
end loop;
end loop;
end Sort;
end Shell;
|