what is the difference between partial_sort and n_th_element?

Discussion in 'C++' started by puzzlecracker, Oct 12, 2008.

  1. NOT SURE WHEN TO USE WHICH
     
    puzzlecracker, Oct 12, 2008
    #1
    1. Advertising

  2. puzzlecracker

    Ian Collins Guest

    puzzlecracker wrote:
    > NOT SURE WHEN TO USE WHICH


    Which what?

    --
    Ian Collins
     
    Ian Collins, Oct 12, 2008
    #2
    1. Advertising

  3. puzzlecracker

    Bo Persson Guest

    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
     
    Bo Persson, Oct 12, 2008
    #3
  4. puzzlecracker

    Guest

    On Oct 12, 4:26 pm, "Bo Persson" <> 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 ?
     
    , Oct 13, 2008
    #4
  5. puzzlecracker

    Zeppe Guest

    wrote:
    > On Oct 12, 4:26 pm, "Bo Persson" <> 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
     
    Zeppe, Oct 13, 2008
    #5
    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. jakk
    Replies:
    4
    Views:
    12,511
  2. Santa
    Replies:
    1
    Views:
    1,140
    Mark A. Odell
    Jul 17, 2003
  3. Scott Meyers
    Replies:
    0
    Views:
    712
    Scott Meyers
    Mar 17, 2011
  4. PerlFAQ Server
    Replies:
    0
    Views:
    384
    PerlFAQ Server
    Jan 6, 2011
  5. PerlFAQ Server
    Replies:
    0
    Views:
    294
    PerlFAQ Server
    Apr 15, 2011
Loading...

Share This Page