5(a)Sorting AlgorithmsEasy1 mark
A programmer has defined a global 1D array Numbers of type INTEGER, which can store 1000 integers. The lower bound of the array Numbers is set to 1. Each element of the array has been initialised with a random integer in the range 200 to 99 999.
The programmer has written a bubble sort algorithm to sort the array Numbers into ascending order.
Study algorithm A. Assume all the variables have been correctly declared.
algorithm A:
FOR LoopCounter ← 1 TO 999 //Outer LoopFOR Index ← 1 TO 999 //Inner LoopIF Numbers[Index] > Numbers[Index + 1] THEN//Start of block to swap neighbouring elements in the arrayTemp ← Numbers[Index]Numbers[Index] ← Numbers[Index + 1]Numbers[Index + 1] ← Temp//End of block to swap neighbouring elements in the arrayENDIFNEXT IndexNEXT LoopCounter
Describe the change that would have to be made to the bubble sort algorithm (algorithm A) so that the Numbers array would be sorted into descending order.
Answer
0 words