How would I write function thats alinear search followed by a "move to front" of the found item with the following pre and post.
boolean movetoFrontSearch (
int a[], an array of size MAX
int n, the number of actual elements in the array
int target, value to be "searched for"
}
pre: n+1 <= MAX
post: { (RETURN = TRUE) => a[0] = target } and
{( RETURN = FALSE) => target not in a'[0...n-1]
and a[n] = target and
a'[0...n-1]=a[0..n-1] }
I know that targets that are not in the array should be inserted at the end of the array. Any help would be appreciated.
boolean movetoFrontSearch (
int a[], an array of size MAX
int n, the number of actual elements in the array
int target, value to be "searched for"
}
pre: n+1 <= MAX
post: { (RETURN = TRUE) => a[0] = target } and
{( RETURN = FALSE) => target not in a'[0...n-1]
and a[n] = target and
a'[0...n-1]=a[0..n-1] }
I know that targets that are not in the array should be inserted at the end of the array. Any help would be appreciated.