summaryrefslogtreecommitdiff
path: root/insertion.adb
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2015-10-15 21:18:48 +1100
committerJed Barber <jjbarber@y7mail.com>2015-10-15 21:18:48 +1100
commita7a0c2924c68c7dc457debb60f44bffc4aa80682 (patch)
tree9856d3765a3c0929624e4a397e0eec61dee45a04 /insertion.adb
parent3e30658ec5ca3ade4f9295129729127a30b4addf (diff)
Added cocktail, insertion, strand sorts
Diffstat (limited to 'insertion.adb')
-rw-r--r--insertion.adb29
1 files changed, 29 insertions, 0 deletions
diff --git a/insertion.adb b/insertion.adb
new file mode 100644
index 0000000..863fb8e
--- /dev/null
+++ b/insertion.adb
@@ -0,0 +1,29 @@
+
+
+package body Insertion is
+
+
+ procedure Sort(Arr : in out Array_T) is
+ Place : Index_T;
+ Temp : Element_T;
+ begin
+ if Arr'Length <= 1 then
+ return;
+ end if;
+
+ for I in Index_T range Index_T'Succ(Arr'First) .. Arr'Last loop
+ if Arr(Index_T'Pred(I)) > Arr(I) then
+ Place := I;
+ while Place /= Arr'First and then Arr(Index_T'Pred(Place)) > Arr(I) loop
+ Place := Index_T'Pred(Place);
+ end loop;
+ Temp := Arr(I);
+ Arr(Index_T'Succ(Place) .. I) := Arr(Place .. Index_T'Pred(I));
+ Arr(Place) := Temp;
+ end if;
+ end loop;
+ end Sort;
+
+
+end Insertion;
+