Sorting of numbers or strings.

Discussion in 'C Programming' started by Mars, Mar 2, 2005.

  1. Mars

    Mars Guest

    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??
    Mars, Mar 2, 2005
    #1
    1. Advertising

  2. Mars

    CBFalconer Guest

    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
    CBFalconer, Mar 2, 2005
    #2
    1. Advertising

  3. In article <4225e691$-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....

    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.
    Walter Roberson, Mar 2, 2005
    #3
  4. Mars

    Eric Sosman Guest

    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.

    --
    Eric Sosman, Mar 2, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Carsten Zerbst
    Replies:
    6
    Views:
    6,801
    Roedy Green
    Aug 14, 2003
  2. Replies:
    6
    Views:
    308
    Amit Khemka
    Sep 25, 2007
  3. Delaney, Timothy (Tim)

    RE: sorting a list numbers stored as strings

    Delaney, Timothy (Tim), Sep 25, 2007, in forum: Python
    Replies:
    4
    Views:
    411
  4. Jack Bauer

    Sorting numbers as strings

    Jack Bauer, May 18, 2009, in forum: Ruby
    Replies:
    13
    Views:
    245
    Johan Holmberg
    May 20, 2009
  5. one man army

    Numbers to strings to numbers again

    one man army, Dec 28, 2005, in forum: Javascript
    Replies:
    6
    Views:
    139
    one man army
    Dec 30, 2005
Loading...

Share This Page