Jump to content

Sorting algorithms/Selection sort: Difference between revisions

Add BCPL
m (→‎{{header|REXX}}: added an EXIT code.)
(Add BCPL)
Line 742:
460 END
</lang>
 
=={{header|BCPL}}==
<lang BCPL>get "libhdr"
 
let selectionsort(A, len) be if len > 1
$( let minloc = A and t = ?
for i=0 to len-1
if !minloc > A!i do minloc := A+i
t := !A
!A := !minloc
!minloc := t
selectionsort(A+1, len-1)
$)
 
let writearray(A, len) be
for i=0 to len-1 do
writed(A!i, 6)
 
let start() be
$( let array = table 52, -5, -20, 199, 65, -3, 190, 25, 9999, -5342
let length = 10
writes("Input: ") ; writearray(array, length) ; wrch('*N')
selectionsort(array, length)
writes("Output: ") ; writearray(array, length) ; wrch('*N')
$)</lang>
{{out}}
<pre>Input: 52 -5 -20 199 65 -3 190 25 9999 -5342
Output: -5342 -20 -5 -3 25 52 65 190 199 9999</pre>
 
=={{header|C}}==
2,114

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.