Sorting a set of numbers.... I should remember this....

This is a discussion on Sorting a set of numbers.... I should remember this.... within the C Programming forums, part of the General Programming Boards category; Hi Sorry for such a trivial question (this has to come up in the first semester of any comp-sci course), ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    15

    Sorting a set of numbers.... I should remember this....

    Hi

    Sorry for such a trivial question (this has to come up in the first semester of any comp-sci course), but I need to sort a string of numbers, no longer than 32 digits each, in "dictionary order".

    So

    11111111
    112
    131
    4
    52343
    53

    like in a dictionary you have a, with aa before ab, then b, c, d etc.

    Thanks!

  2. #2
    Registered User
    Join Date
    Dec 2008
    Posts
    104
    but what exactly do you want to do with the strings after they're in order? place them in a vector?

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    If you have strings and you want to compare them/sort them, as strings, then you'll want to use strcmp(string1, string2), where the returned value will indicate which is greater. (Positive 1 means right side is greater, negative 1 means left side is greater than right.)

    Code:
    int comp;
    comp = strcmp(string1, string2);

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,796
    Quote Originally Posted by Adak
    (Positive 1 means right side is greater, negative 1 means left side is greater than right.)
    Strictly speaking 1 and -1 are not necessarily the values that will be returned; the C standard only requires some positive and some negative integer respectively.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need some help...
    By darkconvoy in forum C Programming
    Replies: 32
    Last Post: 04-29-2008, 03:33 PM
  2. C help for network animator
    By fastshadow in forum Tech Board
    Replies: 7
    Last Post: 03-17-2006, 02:44 AM
  3. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  5. "if you love someone" :D
    By Carlos in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 10-02-2003, 01:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21