Or login with:
#include <algorithm> template < class RandomAccessIterator > void sort_heap( RandomAccessIterator first, RandomAccessIterator last ); template < class RandomAccessIterator, class Predicate > void sort_heap( RandomAccessIterator first, RandomAccessIterator last, Predicate comp );Parameters:
| Parameter | Description |
|---|---|
| first | A random-access iterator addressing the position of the first element in the target heap |
| last | A random-access iterator addressing the position one past the final element in the target heap |
| comp | User-defined predicate function object that defines sense in which one element is less than another. A binary predicate takes two arguments and returns true when satisfied and false when not satisfied |
operator< and the second compares objects using a function object comp.#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int a[] = {100, 19, 36, 17, 3, 25, 1, 2, 7}; vector<int> v(a, a+9); cout <<"\nHere are the values in the heap:\n"; for (vector<int>::size_type i=0; i<v.size(); i++) cout <<v.at(i)<<" "; cout <<"\nNow we sort these values into ascending order."; sort_heap(v.begin(), v.end()); cout <<"\nHere is the result:\n"; for (vector<int>::size_type i=0; i<v.size(); i++) cout <<v.at(i)<<" ";
You must login to leave a messge