Daniel B. answered 10/17/21
PhD in Computer Science with 42 years in Computer Research
This code will fail if the largest element is in position 0, because then the if-statement is never
executed and largestPos remains uninitialized.
I assume your goal is to maintain the invariant
arraySequence.get(largestPos) = temp
To make it true, largestPos must be initialized to 0.
Secondly the body of the if-statement must assign the newly discovered larger element to temp.