inplace_merge
Merges two consecutive sorted ranges
Definition
The inplace_merge() algorithm is defined in the standard header <algorithm> and in the nonstandard backward-compatibility header <algo.h>.
Interface
#include <algorithm>
template < class BidirectionalIterator >
void inplace_merge(
BidirectionalIterator first,
BidirectionalIterator middle,
BidirectionalIterator last
);
template < class BidirectionalIterator, class Predicate >
void inplace_merge(
BidirectionalIterator first,
BidirectionalIterator middle,
BidirectionalIterator last,
Predicate comp
);Parameters:
| Parameter | Description |
| first | A bidirectional iterator addressing the position of the first element in the first of two consecutive sorted ranges to be combined and sorted into a single range |
| middle | A bidirectional iterator addressing the position of the first element in the second of two consecutive sorted ranges to be combined and sorted into a single range |
| last | A bidirectional iterator addressing the position one past the last element in the second of two consecutive sorted ranges to be combined and sorted into a single range |
| comp | User-defined predicate function object that defines the sense in which one element is greater than another. The binary predicate takes two arguments and should return true when the first element is less than the second element and false otherwise |
Description
Inplace_merge function merges two consecutive sorted ranges [first, middle) and [middle, last) into one sorted range [first, last). The order of equal elements is guaranteed to be preserved.
The first version compares objects using operator<, and the second compares objects using a function object comp.
Return Value
None.
Complexity
The complexity is linear; performs (last - first) - 1 if enough additional memory is available.
Otherwise, is N log(N), where N = last - first.
CodeCogs®