-
Notifications
You must be signed in to change notification settings - Fork 0
/
bubble_sort.adb
32 lines (31 loc) · 1.16 KB
/
bubble_sort.adb
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
with Safe_Swap; use Safe_Swap;
package body Bubble_Sort with
SPARK_Mode
is
procedure Sort (L : in out Nat_Array) is
begin
--pragma Assert (for all X of L => (for some Y of L => X = Y));
for J in reverse L'Range loop
pragma Loop_Invariant
(for all X in L'First .. J =>
(for all Y in J .. L'Last => (if Y > J then L (X) <= L (Y))));
pragma Loop_Invariant
(for all X in J .. L'Last =>
(for all Y in X .. L'Last => (L (X) <= L (Y))));
for I in L'First .. J loop
pragma Loop_Invariant
(for all X in L'First .. J =>
(for all Y in J .. L'Last => (if Y > J then L (X) <= L(Y))));
pragma Loop_Invariant
(for all X in J .. L'Last =>
(for all Y in X .. L'Last => (L (X) <= L (Y))));
pragma Loop_Invariant
(for all X in L'First .. I => L (X) <= L (I));
if I < J and then L (I) > L (I + 1) then
Swap(L, I, I+1);
end if;
pragma Assert (if I < J then L (I) <= L (I + 1));
end loop;
end loop;
end Sort;
end Bubble_Sort;