STL algorithm inplace_merge (24)

Source: Internet
Author: User

Inplace_merge prototype:

STD: inplace_merge
Default (1)
template <class BidirectionalIterator>  void inplace_merge (BidirectionalIterator first, BidirectionalIterator middle,                      BidirectionalIterator last);
Custom (2)
template <class BidirectionalIterator, class Compare>  void inplace_merge (BidirectionalIterator first, BidirectionalIterator middle,                      BidirectionalIterator last, Compare comp);
This function combines the ordered sequences [first, middle) and [Middle, last) into an ordered sequence.

The two cells must be sorted and all use the same sorting rule.

Note that first, middle, and last are all in the same container, but they are separated into two intervals.

A simple example:

#include <iostream>#include <vector>#include <array>#include <algorithm>using namespace std;void inplacemerge(){    vector<int> vi{1,5,8,19,1,8,56};    cout<<"at first,vi=";    for_each(vi.begin(),vi.end(),[](int i){cout<<i<<" ";});    cout<<endl;    inplace_merge(vi.begin(),vi.begin()+4,vi.end());    cout<<"after inplace_merge(vi.begin(),vi.begin()+4,vi.end());,vi="<<endl;;    for_each(vi.begin(),vi.end(),[](int i){cout<<i<<" ";});    cout<<endl;}
Run:



------------------------------------------------------------------

// For more instructions on writing errors or poor information, you can leave a message below or click the email address in the upper left corner to send an email to me, pointing out my errors and deficiencies, so that I can modify them, thank you for sharing it.

Reprinted please indicate the source: http://blog.csdn.net/qq844352155

Author: unparalleled

Email: [email protected]

Yu gdut

------------------------------------------------------------------


STL algorithm inplace_merge (24)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.