Sorting algorithms/Insertion sort: Difference between revisions

Line 4,522:
return blist
</syntaxhighlight>
 
=={{header|RPL}}==
{{trans|Python}}
{{works with|Halcyon Calc|4.2.7}}
{| class="wikitable"
! RPL code
! Comment
|-
|
≪ 'A' STO
2 A SIZE '''FOR''' ii
A ii GET
ii 1 -
'''WHILE '''
'''IFERR''' DUP2 A SWAP GET < '''THEN''' 3 DROPN 0 '''END REPEAT'''
'A' OVER GETI PUT
1 -
'''END '''
'A' SWAP 1 + ROT PUT
'''NEXT '''
A 'A' PURGE
≫ 'ISORT' STO
|
''( [array] -- [array] ) ''
for i from 2 to length[A] do ''// RPL arrays starts at 1''
value := A[i]
j := i-1
while
j > 0 and A[j] > value do
A[j+1] := A[j]
j := j-1
done
A[j+1] = value
done
Display result and delete global variable
|}
{{in}}
<pre>
[ 1 4 -1 0 3 7 4 8 20 -6 ] ISORT
</pre>
{{out}}
<pre>
1: [ -6 -1 0 1 3 4 4 7 8 20 ]
</pre>
 
=={{header|Ruby}}==
1,150

edits