CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2006
    Location
    croatia
    Posts
    88

    partial_sort() thing

    I was just wondering how does the partial_sort() places the unsorted elements.
    Consider I wanna sort this vector.

    2 3 1 5 6 2 4 7 9 12 3 11

    from begin() to begin()+5

    So the output would be (tested):

    1 2 2 3 3 6 5 7 9 12 4 11

    and when I put sort from begin() to begin()+6 I get:

    1 2 2 3 3 4 6 7 9 12 5 11

    Are the elements that dont get into sorted sequence placed randomly?
    Because, I see no evidence that their positions have remained unchanged related to each other. If so, the first sort would yield:

    1 2 2 3 3 5 6 4 7 9 12 11
    and not
    1 2 2 3 3 6 5 7 9 12 4 11

    Thanks for replies.

  2. #2
    Join Date
    Dec 2004
    Location
    Poland
    Posts
    1,165

    Re: partial_sort() thing

    If I get things right, standard says:

    25.3.1.3
    ...
    Code:
    template<class RandomAccessIterator, class Compare>
    void partial_sort(RandomAccessIterator first,
       RandomAccessIterator middle,
       RandomAccessIterator last,
       Compare comp);
    Effects: Places the first middle - first sorted elements from the range [first, last) into the range [first, middle). The rest of the elements in the range [middle, last) are placed in an unspecified order.
    So, order in which 'unsorted' elements are placed, is not determined and implemntation - dependant.

    Regards,
    Hob
    Last edited by Hobson; February 18th, 2006 at 04:31 PM.
    B+!
    'There is no cat' - A. Einstein

    Use &#91;code] [/code] tags!

    Did YOU share your photo with us at CG Members photo gallery ?

  3. #3
    Join Date
    Jan 2006
    Location
    croatia
    Posts
    88

    Re: partial_sort() thing

    Thanks.
    I must have misread the
    The rest of the elements in the range [middle, last) are placed in an unspecified order.
    part.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured