DEFINE listToSort AS a list of integers containing the numbers 1 to 20
SET lengthOfList TO the length of listToSort
FOR currentIndex FROM 0 TO lengthOfList - 1 DO
FOR innerIndex FROM 0 TO lengthOfList - 1 - currentIndex DO
IF listToSort[innerIndex] > listToSort[innerIndex + 1] THEN
TEMP ← listToSort[innerIndex]
listToSort[innerIndex] ← listToSort[innerIndex + 1]
listToSort[innerIndex + 1] ← TEMP
END IF
END FOR
END FOR
|
DEFINE listToSort AS a list of integers containing the numbers 1 to 20
SET lengthOfList TO the length of listToSort
FOR currentIndex FROM 1 TO lengthOfList - 1 DO
SET currentValue TO listToSort[currentIndex]
SET innerIndex TO currentIndex - 1
WHILE innerIndex >= 0 AND listToSort[innerIndex] > currentValue DO
listToSort[innerIndex + 1] ← listToSort[innerIndex]
SET innerIndex TO innerIndex - 1
END WHILE
listToSort[innerIndex + 1] ← currentValue
END FOR
|