source: CIVL/examples/loop_invariants/dev/selectSort.cvl

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 944 bytes
Line 
1#include <assert.h>
2#pragma CIVL ACSL
3$input int N;
4$assume(N > 0);
5int a[N];
6
7int main() {
8 int i, j;
9 int minIdx = 0;
10
11 $havoc(&a);
12
13 /*@ loop invariant 0 <= i && i <= N;
14 @ loop invariant \forall int t; N-i+1<=t && t <N ==>
15 @ a[t] <= a[t-1];
16 @ loop invariant \forall int t; 0 <= t && t < N-i && i > 0 ==>
17 @ a[t] >= a[N-i];
18 @ loop assigns i, j, a[0 .. N-1];
19 @*/
20 for (i = 0; i < N; i++) {
21 /*@ loop invariant 0<=j && j <=N-i && 0<=minIdx &&
22 @ minIdx<N-i;
23 @ loop invariant \forall int t; 0<=t && t <j ==>
24 @ a[t] >= a[minIdx];
25 @ loop assigns j, minIdx;
26 @*/
27 for (j = 0; j < N-i; j++)
28 if (a[j] < a[minIdx])
29 minIdx = j;
30
31 int tmp = a[minIdx];
32
33 a[minIdx] = a[N-i-1];
34 a[N-i-1] = tmp;
35 minIdx = 0;
36 }
37 assert($forall (int i : 1 .. N-1) a[i] <= a[i-1]);
38 return 0;
39}
Note: See TracBrowser for help on using the repository browser.