An algorithm is designed to sort a 2D array of runners by their marathon times in ascending order.
1 # runners has the format [runnerID, name, raceTime]
2
3 PROCEDURE bubbleSortRunners()
4 SET temp TO []
5 FOR i FROM 0 TO LENGTH(runners) - 1 DO
6 FOR j FROM 0 TO LENGTH(runners) - 1 DO
7 IF runners[j, 2] > runners[j + 1, 2] THEN
8 SET temp TO runners[j]
9 SET runners[j] TO runners[j + 1]
10 SET runners[j + 1] TO temp
11 END IF
12 END FOR
13 END FOR
14 END PROCEDURE
The algorithm currently contains an error on line 6 that causes an 'index out of bounds' error when it is run.
Give a new line of code that will correct the error on line 6.
51 exam-style questions on Edexcel GCSE Computer Science Develop code, covering Decomposition and abstraction to solve problems, Read, write, analyse and refine programs, Converting algorithms into programs, Techniques for readable, maintainable code, Identifying and correcting program errors, and Evaluating program fitness and efficiency. Each one has a worked solution and a mark scheme showing where the marks go.