diff options
Diffstat (limited to 'sort/shell.adb')
-rw-r--r-- | sort/shell.adb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/sort/shell.adb b/sort/shell.adb new file mode 100644 index 0000000..6e9cc22 --- /dev/null +++ b/sort/shell.adb @@ -0,0 +1,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; + |