
242 PUZZLE 61 SORT A STRING
PUZZLE
61 SORT A STRING
Tony Wilton posted this quick problem in 2003. We are currently writing
a stored procedure that generates a string of characters in the form
‘
CABBDBC’. We need to be able to sort this string alphabetically, that is,
“
ABBBCCD” as the results. There are no library functions to do this.
Let’s make the assumption that when Tony said “in the form,” he
means the string is always
CHAR(7) and always made up of elements of
the four letters {
'A', 'B', 'C', 'D'}.
Answer #1
The first answers proposed by people were for a procedure with a WHILE
loop written in a proprietary 4GL. They used bubble sorts on
SUBSTRING ...