How arrange names alphabetically?

This is a discussion on How arrange names alphabetically? within the C++ Programming forums, part of the General Programming Boards category; Hello: I have a txt file of many names, they arranged randomly. Say they are: XYZ ACD ABC OPQ RST ...

  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
    682
    Insert them into std::set (elements are stored sorted) and then iterate through its elements.
    I never put signature, but I decided to make an exception.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,304
    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,304
    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, 01: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, 05: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, 11:15 AM

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