

 Thread Tools  Search this Thread 
#1
 
 
Use of the sort_heap() in C++ I has just started for learning the C++ programming language. I think that the programming in C++ can be easier as compared to C language. I can have the idea about the C++ functions. So, I would like to know about the sort_heap() function of the C++ language. I also would like to know the Use of the sort_heap() function in the C++ coding. Can anyone knows about the sort_heap() function of C++ language. 
#2
 
 
The sort_heap() in C++ The sort_heap() function can be used in the C++ language to rearrange an elements in the given specified range of the heap as [fst,lst) in such a manner that they can form a range that can be sorted. The comparisons can be performed using less than operator "<" for the first version and cmp variable for the second version. The following can be the syntax of the sort_heap() in the C++ language : Code: template <class RndmAcsItrtr> void sort_heap ( RndmAcsItrtr fst, RndmAcsItrtr lst ); 
#3
 
 
Use of the sort_heap() in C++ The following can be the parameters of the sort_heap() function in the C++ language : 1. cmp : This parameter of the sort_heap() function of the C++ language can holds an object of the comparison function that can taking the two values of the similar type than that those can consisted in the given specified range. 2. fst, lst : These parameters of the sort_heap() function of the C++ language can holds the randomAccess iterators to the final and starting positions of the given specified range of the heap that can be sorted. 
#4
 
 
The sort_heap() I can suggest you that to carefully go through the following code of lines that can demonstrates you how to use the sort_heap() function in the C++ programming as follows : Code: #include <iostream> #include <algorithm> #include <vector> using namespace std; int main () { int mt[] = {10,20,30,5,15}; vector<int> z(mt,mt+5); vector<int>::iterator x; make_heap (z.begin(),z.end()); cout << "initial max heap : " << z.front() << endl; pop_heap (z.begin(),z.end()); z.pop_back(); cout << "max heap after pop : " << z.front() << endl; z.push_back(99); push_heap (z.begin(),z.end()); cout << "max heap after push: " << z.front() << endl; sort_heap (z.begin(),z.end()); cout << "final sorted range :"; for (unsigned j=0; j<z.size(); j++) cout << " " << z[j]; cout << endl; return 0; } Code: initial max heap : 30 max heap after pop : 20 max heap after push: 99 final sorted range : 5 10 15 20 99 
#5
 
 
Use of the sort_heap() in C++ The sort_heap() function can converts the heap that can be defined by the range [strt,nd) into a given range that can be sorted. If the weak sequencing comparison function object can be given then the sort_heap() function can used instead of the less than operator to compare an elements. The sort_heap() function can have two properties as follows :


Tags: algorithm, cpp, functions, header files, sort_heap 
Thread Tools  Search this Thread 
