[1] A heap is a particular way of ordering the elements in a range of Random Access Iterators
sort_heap
Category: algorithms
Component type: function
template <class RandomAccessIterator>
void sort_heap(RandomAccessIterator first, RandomAccessIterator last);
template <class RandomAccessIterator, class StrictWeakOrdering>
void sort_heap(RandomAccessIterator first, RandomAccessIterator last, StrictWeakOrdering comp);
The two versions of
Defined in the standard header algorithm, and in the nonstandard backward-compatibility header algo.h.
For the first version, the one that takes two arguments:
• The ordering on objects of
For the second version, the one that takes three arguments:
For the first version, the one that takes two arguments:
For the second version, the one that takes three arguments:
At most
int main() {
int A[] = {1, 4, 2, 8, 5, 7};
const int N = sizeof(A) / sizeof(int);
make_heap(A, A+N);
copy(A, A+N, ostream_iterator<int>(cout, ' '));
cout << endl;
sort_heap(A, A+N);
copy(A, A+N, ostream_iterator<int>(cout, ' '));
cout << endl;
}
[1] A heap is a particular way of ordering the elements in a range of Random Access Iterators
is_heap
Category: algorithms
Component type: function
template <class RandomAccessIterator>
bool is_heap(RandomAccessIterator first, RandomAccessIterator last);
template <class RandomAccessIterator, class StrictWeakOrdering>
inline bool is_heap(RandomAccessIterator first, RandomAccessIterator last, StrictWeakOrdering comp)