i = 0 while i < n and A[i] < x i = i + 1 if i < n and A[i] == x return i else return 'NOT FOUND'
| 11 | 17 | 19 | 28 | 33 | 34 | 40 | 42 | 46 | 51 | 57 |
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
In your definition, be precise and try not to use the word "max" but rather define it in terms of basic comparisons like greater-than or less-than.
percolateMax(A,n) /* A is an array of n integers */
i = 0
while i < n - 1 do
if A[i] > A[i+1]
swap(A[i],A[i+1])
i = i + 1
return A[n-1]