Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Sorting of numbers or strings.

Reply
Thread Tools

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??
 
Reply With Quote
 
 
 
 
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
"Reply" at the bottom of the article headers." - Keith Thompson

 
Reply With Quote
 
 
 
 
Walter Roberson
Guest
Posts: n/a
 
      03-02-2005
In article <4225e691$>, 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....

Which part are you asking for assistance on? Reading values?
Deciding whether they are all numeric? Sorting?
--
Those were borogoves and the momerathsoutgrabe completely mimsy.
 
Reply With Quote
 
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.

--


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting list vs sorting vector boltar2003@boltar.world C++ 2 07-06-2010 09:40 AM
fired event Sorting which wasn't handled - sorting and SelectedIndexChanged Jason ASP .Net Web Controls 0 10-04-2006 02:19 PM
sorting number in ascending way but still mixes the numbers Richard ASP .Net 4 08-05-2004 07:11 AM
sorting by multiple criterias (sub-sorting) Tom Kirchner Perl Misc 3 10-11-2003 05:16 PM
Sorting strings with characters and numbers Carsten Zerbst Java 6 08-14-2003 08:36 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57