Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > what is the difference between partial_sort and n_th_element?

Reply
Thread Tools

what is the difference between partial_sort and n_th_element?

 
 
puzzlecracker
Guest
Posts: n/a
 
      10-12-2008
NOT SURE WHEN TO USE WHICH
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      10-12-2008
puzzlecracker wrote:
> NOT SURE WHEN TO USE WHICH


Which what?

--
Ian Collins
 
Reply With Quote
 
 
 
 
Bo Persson
Guest
Posts: n/a
 
      10-12-2008
puzzlecracker wrote:
> NOT SURE WHEN TO USE WHICH


Using partial_sort will actually sort the first part of the sequence,
nth_element will not. It just separates the elements in "before" and
"after", but in no particular order.


Bo Persson


 
Reply With Quote
 
PeterAPIIT@gmail.com
Guest
Posts: n/a
 
      10-13-2008
On Oct 12, 4:26*pm, "Bo Persson" <(E-Mail Removed)> wrote:
> puzzlecracker wrote:
> > NOT SURE WHEN TO USE WHICH

>
> Using partial_sort will actually sort the first part of the sequence,
> nth_element will not. It just separates the elements in "before" and
> "after", but in no particular order.
>



Can you explain with example ?

 
Reply With Quote
 
Zeppe
Guest
Posts: n/a
 
      10-13-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> On Oct 12, 4:26 pm, "Bo Persson" <(E-Mail Removed)> wrote:
>> puzzlecracker wrote:
>>> NOT SURE WHEN TO USE WHICH

>> Using partial_sort will actually sort the first part of the sequence,
>> nth_element will not. It just separates the elements in "before" and
>> "after", but in no particular order.
>>

>
>
> Can you explain with example ?
>


sequence = [5 6 3 2 4 5 6 7];
|
nth

if I do partial_sort with n = 4, the elements 0,..,4 (before and
including position n) will be sorted, the 5,..,7 will not be
necessarily, that is, a possible outcome is:
[2 3 4 5 5 6 7 6]
|
nth

if I do nth_element, not even the elements strictly before position n
will be sorted, but they will be all less or equal to the nth. A
possible outcome is:
[2 4 5 3 5 6 7 6]
|
nth

If you have full-sort, every element is in its "sorted" position. If you
have partial sort, the first n elements will be in their sorted
position. If you have nth_element, only the nth element is in its sorted
position.

Best wishes,

Zeppe

 
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
FAQ 7.17 What's the difference between dynamic and lexical (static) scoping? Between local() and my()? PerlFAQ Server Perl Misc 0 04-15-2011 04:00 AM
nth_element + sort versus partial_sort Scott Meyers C++ 0 03-17-2011 03:22 AM
FAQ 7.17 What's the difference between dynamic and lexical (static) scoping? Between local() and my()? PerlFAQ Server Perl Misc 0 01-06-2011 05:00 PM
Difference between bin and obj directories and difference between project references and dll references jakk ASP .Net 4 03-22-2005 09:23 PM
Exact difference between 'const char *' and 'char *', also diff between 'const' and 'static' Santa C Programming 1 07-17-2003 02:10 PM



Advertisments