Sorting of numbers or strings.

M

Mars

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??
 
C

CBFalconer

Mars said:
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
 
W

Walter Roberson

: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....

Which part are you asking for assistance on? Reading values?
Deciding whether they are all numeric? Sorting?
 
E

Eric Sosman

Mars said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top