Created
March 12, 2013 16:19
-
-
Save jbranchaud/5144291 to your computer and use it in GitHub Desktop.
An array find method verification from http://rjoshi.org/cs116/homework/hw1-find.dfy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
method find(A:array<int>, key: int) returns (k:int) | |
requires A != null && A.Length > 0 ; | |
requires A[0] < A[A.Length-1] ; | |
ensures 0 <= k < A.Length-1 ; | |
ensures A[k] < A[k+1] ; | |
{ | |
var i:int := 0; | |
while(i < A.length) { | |
if(A[i] == key) { | |
return i; | |
} | |
i := i+1; | |
} | |
return i; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment