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.
Practise OCR GCSE Computer Science Searching and sorting algorithms with exam-style questions for GCSE Computer Science. 36 questions, matched to the OCR GCSE Computer Science (J277) specification and written in Component 01 and Component 02 style. Every question includes a full worked solution and mark scheme, so you can see where marks are awarded rather than just whether you got the answer right.