The trace table shown has been started for this algorithm. The inputs are 23, 17, 31, 19 and -1, in that order.
Count ← 0
INPUT Reading
Min ← Reading
Max ← Reading
WHILE Reading <> -1 DO
Count ← Count + 1
IF Reading < Min
THEN
Min ← Reading
ENDIF
IF Reading > Max
THEN
Max ← Reading
ENDIF
INPUT Reading
ENDWHILE
OUTPUT Count, " ", Min, " ", Max
Give the values that would be written in the rest of each column, in order.
Model answer
Reading: 17, 31, 19, -1
Count: 1, 2, 3, 4
Min: 17
Max: 31
OUTPUT: 4 17 31
Explanation
The first reading sets both Min and Max to 23. Inside the loop each reading is counted and compared, then the next reading is input at the end of the pass. When -1 is input, the WHILE condition is false, so -1 is never counted or treated as the minimum - this is why the rogue value is tested before it is processed.