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)