Going forward, but gently...
This commit is contained in:
parent
4a30965654
commit
97a81f159a
4 changed files with 36 additions and 8 deletions
|
@ -5,6 +5,16 @@ int max_dist(int *tab, unsigned int n)
|
|||
int min = tab[0];
|
||||
int max = tab[0];
|
||||
unsigned int i = 1;
|
||||
|
||||
/*@
|
||||
loop assigns i, max, min;
|
||||
loop invariant I1: \at(i, LoopEntry) <= i <= n;
|
||||
loop invariant I2: min <= max;
|
||||
loop invariant I3: \forall integer j; (\at(i, LoopEntry) <= j < i ==> max >= tab[j] >= min);
|
||||
loop invariant I4: \exists integer j; ( 0 < j < i ==> max == tab[j]);
|
||||
loop invariant I5: \exists integer j; ( 0 < j < i ==> min == tab[j]);
|
||||
loop variant n - i;
|
||||
*/
|
||||
while (i < n)
|
||||
{
|
||||
if (tab[i] < min)
|
||||
|
@ -14,4 +24,4 @@ int max_dist(int *tab, unsigned int n)
|
|||
i++;
|
||||
}
|
||||
return max - min;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue