Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 05-03-2010
Member
 
Join Date: Dec 2009
Posts: 28
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.
Reply With Quote
  #2  
Old 05-03-2010
Member
 
Join Date: Feb 2008
Posts: 1,848
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.
Reply With Quote
  #3  
Old 05-03-2010
Member
 
Join Date: Jan 2008
Posts: 1,515
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 re-sequence 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 );
Reply With Quote
  #4  
Old 05-03-2010
Member
 
Join Date: Apr 2008
Posts: 1,948
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 greater-than heaped version of w1 is ( " ;
   for ( It1 = w1.begin( ) ; It1 != w1.end( ) ; It1++ )
      cout << *It1 << " ";
   cout << ")." << endl;
}
Output
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 greater-than heaped version of w1 is ( 0 1 5 2 6 8 7 3 4 9 ).
Reply With Quote
  #5  
Old 05-03-2010
Member
 
Join Date: May 2008
Posts: 2,008
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 Random-Access 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).
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search



All times are GMT +5.5. The time now is 05:08 PM.