summaryrefslogtreecommitdiff
path: root/sort/shell.adb
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2015-10-18 13:19:48 +1100
committerJed Barber <jjbarber@y7mail.com>2015-10-18 13:19:48 +1100
commitfaeec19d3a971efdc94e86c5fc2d59239b04e84a (patch)
tree57e3f911660bf506594b72df1fab4301cfebaa03 /sort/shell.adb
parent63c3043200de6b28a8c192f1b5625940435ea55e (diff)
Added shell, stooge, pancake sorts
Diffstat (limited to 'sort/shell.adb')
-rw-r--r--sort/shell.adb33
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;
+