Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > is this true? sort algo on STL Lists

Reply
Thread Tools

is this true? sort algo on STL Lists

 
 
Bit byte
Guest
Posts: n/a
 
      04-06-2006
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?

 
Reply With Quote
 
 
 
 
Thomas Tutone
Guest
Posts: n/a
 
      04-06-2006

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

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      04-06-2006
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there an STL algo to fill a vector with product of 2 othervectors? Steve555 C++ 12 12-10-2008 01:19 PM
List of lists of lists of lists... =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==?= Python 5 05-15-2006 11:47 AM
Cosine algo, was Re: sqrt algo pete C Programming 108 11-05-2005 05:33 AM
sort STL lists Hagen C++ 1 11-20-2003 10:42 PM
Ado sort error-Ado Sort -Relate, Compute By, or Sort operations cannot be done on column(s) whose key length is unknown or exceeds 10 KB. Navin ASP General 1 09-09-2003 07:16 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57