

 Thread Tools  Search this Thread 
#1
 
 
What can be the use of the make_heap() in C++ I am learning the C++ language. I can not know much more about the C++ language functions and also I can not know how to use the functions. So, I want to know What is the use of the make_heap() function in the C++ language coding. I also want to know How the make_heap() function can be used in the C++ code of lines. Therefore, Anyone can knows about the make_heap() function of the C++ language. 
#2
 
 
What can be the use of the make_heap() in C++ The make_heap() function of the C++ language can be used to convert the the given specified range of an elements such as [strt,nd) into a heap. If an object of the weak sequencing comparison function can be given then it can be used in spite of the less than "<" operator to compare an elements. The make_heap() function can be runs in a linear time in the C++ language. The make_heap() function can be comes under the <algorithm> header files in the C++ language. 
#3
 
 
The use of the make_heap() in C++ The make_heap() function can rearranges an elements in the given specified range as [fst,lst) in such a manner that an elements can form a heap. In order to resequence these elements the make_heap() function can performs the comparisons using an less than operator for the first version and comp variable for the second version. The following can be the syntax of the make_heap() function : Code: template <class RndmAcsItrtr> void make_heap ( RndmAcsItrtr fst, RndmAcsItrtr lst ); 
#4
 
 
The make_heap() The following program can demonstrates you how to implement the make_heap() function of the C++ language in the C++ programming as follows : Code: #include <vector> #include <algorithm> #include <functional> #include <iostream> int main( ) { using namespace std; vector <int> w1, w2; vector <int>::iterator It1, It2; int i; for ( i = 0 ; i <= 9 ; i++ ) { w1.push_back( i ); } random_shuffle( w1.begin( ), w1.end( ) ); cout << "Vector w1 is ( " ; for ( It1 = w1.begin( ) ; It1 != w1.end( ) ; It1++ ) cout << *It1 << " "; cout << ")." << endl; make_heap ( w1.begin( ), w1.end( ) ); cout << "The heaped version of vector w1 is ( " ; for ( It1 = w1.begin( ) ; It1 != w1.end( ) ; It1++ ) cout << *It1 << " "; cout << ")." << endl; make_heap ( w1.begin( ), w1.end( ), greater<int>( ) ); cout << "The greaterthan heaped version of w1 is ( " ; for ( It1 = w1.begin( ) ; It1 != w1.end( ) ; It1++ ) cout << *It1 << " "; cout << ")." << endl; } Code: Vector w1 is ( 8 1 9 2 0 5 7 3 4 6 ). The heaped version of vector w1 is ( 9 6 8 4 1 5 7 3 2 0 ). The greaterthan heaped version of w1 is ( 0 1 5 2 6 8 7 3 4 9 ). 
#5
 
 
Use of the make_heap() in C++ The following can be the parameters of the make_heap() function of the C++ language : 1. cmp : This parameter of the make_heap() function can contains an object of the function that can taking the values of the two of the equivalent type than those consisted in the given specified range. 2. fst, lst : These parameter of the make_heap() function can contains a RandomAccess iterators to final and starting positions of the given sequence that can be transformed in the heap. The range used can be as [fst,lst). 

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