honky tonk
in Miracle World
Firstly, I hate algorithms.
Secondly, how can you tell if the following is a selection or insertion sort? I understand the difference between the two (slightly), but I can't comprehend the algorithms. Here it is:
----------------------------------------------------------
BEGIN MAINPROGRAM
INITIALISATION
set First to first position
set Last to last position
set PositionOfNext to Last - 1
END INITIALISATION
WHILE PositionOfNext >= First
set Next to data at PositionOfNext
set Current to PositionOfNext
WHILE (Current < Last) AND (Next > data at (Current + 1))
increment Current
set data at (Current - 1) to data at Current
ENDWHILE
set data at Current to Next
decrement PositionOfNext
ENDWHILE
END MAINPROGRAM
----------------------------------------------------------
This comes directly from the Excel Software Design and Development textbook, and it's a multiple choice question asking which sort the algorithm represents.
Can anyone help?
Secondly, how can you tell if the following is a selection or insertion sort? I understand the difference between the two (slightly), but I can't comprehend the algorithms. Here it is:
----------------------------------------------------------
BEGIN MAINPROGRAM
INITIALISATION
set First to first position
set Last to last position
set PositionOfNext to Last - 1
END INITIALISATION
WHILE PositionOfNext >= First
set Next to data at PositionOfNext
set Current to PositionOfNext
WHILE (Current < Last) AND (Next > data at (Current + 1))
increment Current
set data at (Current - 1) to data at Current
ENDWHILE
set data at Current to Next
decrement PositionOfNext
ENDWHILE
END MAINPROGRAM
----------------------------------------------------------
This comes directly from the Excel Software Design and Development textbook, and it's a multiple choice question asking which sort the algorithm represents.
Can anyone help?
Last edited: