Sort the letters of string in alphabetical order: Difference between revisions
Sort the letters of string in alphabetical order (view source)
Revision as of 19:12, 24 July 2021
, 2 years agoAdded XPL0 example.
(→{{header|ALGOL 68}}: Added the REXX test string) |
(Added XPL0 example.) |
||
Line 200:
Unsorted->Now is the time for all good men to come to the aid of their country.
Sorted -> .Naaccddeeeeeeffghhhiiiillmmmnnooooooooorrrstttttttuwy
</pre>
=={{header|XPL0}}==
<lang XPL0>string 0; \use zero-terminated strings
func StrLen(Str); \Return number of characters in an ASCIIZ string
char Str;
int I;
for I:= 0 to -1>>1 do
if Str(I) = 0 then return I;
func Sort(Str); \Bubble sort string Str
char Str;
int J, I, T;
[for J:= StrLen(Str)-1 downto 0 do
for I:= 0 to J-1 do
if Str(I) > Str(I+1) then
[T:= Str(I); Str(I):= Str(I+1); Str(I+1):= T];
return Str;
];
[Text(0, Sort("The quick brown fox jumps over the lazy dog."));
CrLf(0);
Text(0, Sort("Pack my box with five dozen liquor jugs."));
CrLf(0);
]</lang>
{{out}}
<pre>
.Tabcdeeefghhijklmnoooopqrrstuuvwxyz
.Pabcdeefghiiijklmnoooqrstuuvwxyz
</pre>
|