Move Maximum
tags: linear-scan adjacent-comparison swap
Move the maximum element to the last location in the input array.
|
|
A common mistake is going out of bounds when scanning the linear array. The upper bound for the index is NOT the last element but the element before the last element.
An alternative way is to compare the value of the current element with the preceding value.
|
|
In this case the upper bound stops at the last element. But the initial value of the index starts from 1.