is this true? sort algo on STL Lists

Discussion in 'C++' started by Bit byte, Apr 6, 2006.

  1. Bit byte

    Bit byte Guest

    I just came accross this : "Note that the STL sort algorithm does NOT
    work for lists; that's why a sort member function is supplied."

    Is this true?
    Has this been fixed in newer versions of the STL?
    Bit byte, Apr 6, 2006
    #1
    1. Advertising

  2. Bit byte wrote:


    > I just came accross this : "Note that the STL sort algorithm does NOT
    > work for lists; that's why a sort member function is supplied."
    >
    > Is this true?


    Yes. std::sort requires random-access iterators, which std::list does
    not supply.

    > Has this been fixed in newer versions of the STL?


    There's nothing to fix. If you need to sort a list, you can use
    std::list's member function std::list::sort, which will do the job.
    That's been the case since the C++ standard was adopted in 1998, and it
    hasn't changed.

    Best regards,

    Tom
    Thomas Tutone, Apr 6, 2006
    #2
    1. Advertising

  3. Bit byte wrote:
    > I just came accross this : "Note that the STL sort algorithm does NOT
    > work for lists; that's why a sort member function is supplied."
    >
    > Is this true?


    Of course. std::sort requires random-access iterators, std::list's
    iterators are not of that kind.

    > Has this been fixed in newer versions of the STL?


    Of course not.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Apr 6, 2006
    #3
    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. Hagen

    sort STL lists

    Hagen, Nov 20, 2003, in forum: C++
    Replies:
    1
    Views:
    349
    Moonlit
    Nov 20, 2003
  2. =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==

    List of lists of lists of lists...

    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==, May 8, 2006, in forum: Python
    Replies:
    5
    Views:
    404
    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==
    May 15, 2006
  3. pete

    Cosine algo, was Re: sqrt algo

    pete, Oct 15, 2005, in forum: C Programming
    Replies:
    108
    Views:
    1,723
  4. Steve555
    Replies:
    12
    Views:
    706
    Steve555
    Dec 10, 2008
  5. bdb112
    Replies:
    45
    Views:
    1,341
    jazbees
    Apr 29, 2009
Loading...

Share This Page