Sorting algorithms/Insertion sort: Difference between revisions
Content deleted Content added
m →{{header|AppleScript}}: Minor relabelling. |
|||
Line 487: | Line 487: | ||
-- put back into the list until either it's superseded or the end of the sort is reached. |
-- put back into the list until either it's superseded or the end of the sort is reached. |
||
set highestSoFar to o's lst's item l |
set highestSoFar to o's lst's item l |
||
set |
set rv to o's lst's item (l + 1) |
||
if (highestSoFar > |
if (highestSoFar > rv) then |
||
set o's lst's item l to |
set o's lst's item l to rv |
||
else |
else |
||
set highestSoFar to |
set highestSoFar to rv |
||
end if |
end if |
||
-- Work through the rest of the range, rotating values back into the sorted group as necessary. |
-- Work through the rest of the range, rotating values back into the sorted group as necessary. |
||
repeat with |
repeat with j from (l + 2) to r |
||
set |
set rv to o's lst's item j |
||
if (highestSoFar > |
if (highestSoFar > rv) then |
||
repeat with |
repeat with i from (j - 2) to l by -1 |
||
set |
set lv to o's lst's item i |
||
if ( |
if (lv > rv) then |
||
set o's lst's item ( |
set o's lst's item (i + 1) to lv |
||
else |
else |
||
set |
set i to i + 1 |
||
exit repeat |
exit repeat |
||
end if |
end if |
||
end repeat |
end repeat |
||
set o's lst's item |
set o's lst's item i to rv |
||
else |
else |
||
set o's lst's item ( |
set o's lst's item (j - 1) to highestSoFar |
||
set highestSoFar to |
set highestSoFar to rv |
||
end if |
end if |
||
end repeat |
end repeat |