Results 1 to 5 of 5

Thread: What can be the use of the make_heap() in C++

  1. #1
    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.

  2. #2
    Join Date
    Feb 2008
    Posts
    1,852

    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. #3
    Join Date
    Jan 2008
    Posts
    1,521

    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 );

  4. #4
    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 ).

  5. #5
    Join Date
    May 2008
    Posts
    2,012

    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).

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,726,827,194.44793 seconds with 15 queries