Velocity Reviews > Sorting of numbers or strings.

Sorting of numbers or strings.

Mars
Guest
Posts: n/a

 03-02-2005
I don't know whether the inputs are all numbers or all strings...
if they are numbers, they are sorted as numbers,
if they are strings, they are sorted as strings....

e.g.

input : 9 12 2 4
output : 2 4 9 12

input : orange Banana
ouput : Banana orange

How can I do so??

CBFalconer
Guest
Posts: n/a

 03-02-2005
Mars wrote:
>
> I don't know whether the inputs are all numbers or all strings...
> if they are numbers, they are sorted as numbers,
> if they are strings, they are sorted as strings....
>
> e.g.
>
> input : 9 12 2 4
> output : 2 4 9 12
>
> input : orange Banana
> ouput : Banana orange
>
> How can I do so??

What are you going to do with:

input : 9 orange 12 2 banana 4

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the

Walter Roberson
Guest
Posts: n/a

 03-02-2005
In article <4225e691\$(E-Mail Removed)-cable.com>, Mars <Mars@Mars> wrote:
:I don't know whether the inputs are all numbers or all strings...
:if they are numbers, they are sorted as numbers,
:if they are strings, they are sorted as strings....

Deciding whether they are all numeric? Sorting?
--
Those were borogoves and the momerathsoutgrabe completely mimsy.

Eric Sosman
Guest
Posts: n/a

 03-02-2005

Mars wrote:
> I don't know whether the inputs are all numbers or all strings...
> if they are numbers, they are sorted as numbers,
> if they are strings, they are sorted as strings....
>
>
> e.g.
>
> input : 9 12 2 4
> output : 2 4 9 12
>
> input : orange Banana
> ouput : Banana orange

You might find

http://sourcefrog.net/projects/natsort/

helpful. (Yes, that's "frog," not "forge.") Last
time I looked, the C implementation had several
occurrences of the "pass a plain `char' to a <ctype.h>
function" error, but those are easily repaired.

--
http://www.velocityreviews.com/forums/(E-Mail Removed)