Sort the letters of string in alphabetical order: Difference between revisions

Add BCPL
(Add BCPL)
Line 51:
{{out}}
<pre> sort 'Now is the time for all good men to come to the aid of their country.'
.Naaccddeeeeeeffghhhiiiillmmmnnooooooooorrrstttttttuwy</pre>
 
=={{header|BCPL}}==
<lang bcpl>get "libhdr"
 
let sortchars(str) be
$( let count = vec 255 and loc = ?
for i=0 to 255 do i!count := 0
for i=1 to str%0 do (str%i)!count := (str%i)!count + 1
loc := 1
for i=0 to 255 until i!count = 0
$( str%loc := i
loc := loc + 1
i!count := i!count - 1
$)
$)
 
let start() be
$( let string =
"Now is the time for all good men to come to the aid of their country."
writef("%S*N", string)
sortchars(string)
writef("%S*N", string)
$)</lang>
{{out}}
<pre>Now is the time for all good men to come to the aid of their country.
.Naaccddeeeeeeffghhhiiiillmmmnnooooooooorrrstttttttuwy</pre>
 
2,093

edits