source: CIVL/examples/loop_invariants/loop_assigns_gen/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: 857 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
10 $havoc(&a);
11 /*@ loop invariant 0 <= i && i <= N;
12 @ loop invariant \forall int t; N-i+1<=t && t <N ==>
13 @ a[t] <= a[t-1];
14 @ loop invariant \forall int t; 0 <= t && t < N-i && i > 0 ==>
15 @ a[t] >= a[N-i];
16 @*/
17 for (i = 0; i < N; i++) {
18 int minIdx = 0;
19 /*@ loop invariant 0<=j && j <=N-i && 0<=minIdx &&
20 @ minIdx<N-i;
21 @ loop invariant \forall int t; 0<=t && t <j ==>
22 @ a[t] >= a[minIdx];
23 @*/
24 for (j = 0; j < N-i; j++)
25 if (a[j] < a[minIdx])
26 minIdx = j;
27
28 int tmp = a[minIdx];
29
30 a[minIdx] = a[N-i-1];
31 a[N-i-1] = tmp;
32 }
33 assert($forall (int i : 1 .. N-1) a[i] <= a[i-1]);
34 return 0;
35}
Note: See TracBrowser for help on using the repository browser.