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

Add CLU
(Added solution for Action!)
(Add CLU)
Line 213:
done...
</pre>
 
=={{header|CLU}}==
<lang clu>% Unicode is explicitly not supported, the standard says
% that "every implementation must provide at least 128,
% but no more than 512, characters".
% That means we can do it in O(N) using a counting sort.
 
sort_string = proc (s: string) returns (string)
char_count: array[int] := array[int]$fill(0,512,0)
for c: char in string$chars(s) do
i: int := char$c2i(c)
char_count[i] := char_count[i]+1
end
sorted_chars: array[char] := array[char]$predict(1,string$size(s))
for i: int in array[int]$indexes(char_count) do
for j: int in int$from_to(1,char_count[i]) do
array[char]$addh(sorted_chars, char$i2c(i))
end
end
return(string$ac2s(sorted_chars))
end sort_string
 
start_up = proc ()
po: stream := stream$primary_output()
str: string := "Now is the time for all good men to come to the aid of their country."
stream$putl(po, str)
stream$putl(po, sort_string(str))
end start_up</lang>
{{out}}
<pre>Now is the time for all good men to come to the aid of their country.
.Naaccddeeeeeeffghhhiiiillmmmnnooooooooorrrstttttttuwy</pre>
 
=={{header|Common Lisp}}==
Line 222 ⟶ 256:
" .Naaccddeeeeeeffghhhiiiillmmmnnooooooooorrrstttttttuwy"
</pre>
 
=={{header|F_Sharp|F#}}==
<lang fsharp>
2,095

edits