Thread: How arrange names alphabetically?

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    12

    How arrange names alphabetically?

    Hello:

    I have a txt file of many names, they arranged randomly. Say they are:
    XYZ
    ACD
    ABC
    OPQ
    RST

    Now I want to re-arrange them alphabetically as:

    ABC
    ACD
    OPQ
    RST
    XYZ

    How to do this, please! --Zhao

  2. #2
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    733
    Insert them into std::set (elements are stored sorted) and then iterate through its elements.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    What you're looking for is called "sorting".
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    Registered User
    Join Date
    Sep 2011
    Posts
    12
    Hi: Not using the sort skill before, I don't know how to start.
    Could you tell me something more?

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    A quick search turns up this as a possible starting point.

    See how you go with adapting the information there to what you have.
    In your next post, be sure to include some code showing the definition of the struct or type of data that you are sorting.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Arrange program?
    By Siaw Ys in forum C Programming
    Replies: 9
    Last Post: 11-27-2011, 02:17 AM
  2. Segmentation Fault in 4 dimensional arrange
    By Tempa in forum C Programming
    Replies: 10
    Last Post: 06-08-2011, 09:16 AM
  3. how to arrange the 361 data in 19x19 box?
    By jimmyymmij in forum C# Programming
    Replies: 10
    Last Post: 01-04-2009, 06:56 PM
  4. Arrange letters of the string alphabetically
    By ama_cuber in forum C Programming
    Replies: 16
    Last Post: 03-19-2008, 03:40 AM
  5. re arrange index of numbers
    By bazzano in forum C Programming
    Replies: 9
    Last Post: 11-03-2005, 12:15 PM