An environmental monitoring system tracks the water acidity of various lake samples. An insertion sort algorithm is implemented in pseudocode to sort a 1D array of these pH measurements, pH_levels, into descending numerical order.
pH_levels = [6.8, 7.4, 5.2, 8.1, 4.5]
for i = 1 to pH_levels.length - 1
ptr = i
while (ptr > 0 and pH_levels[ptr] > pH_levels[ptr - 1])
temp_val = pH_levels[ptr]
pH_levels[ptr] = pH_levels[ptr - 1]
pH_levels[ptr - 1] = temp_val
ptr = ptr - 1
endwhile
next i
Describe the purpose of the variable temp_val in this algorithm.
36 exam-style questions on OCR GCSE Computer Science Searching and sorting algorithms. Each one has a worked solution and a mark scheme showing where the marks go.