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
Use of the push_heap() function in the C++

I like to do the the programming .in C++ language. I had learned the C++ language in the BSC-IT. I can know the actual concept or working of the C++ functions. So, I want to know what is the push_heap() function of the C++ language. I also want to know what is the use of the push_heap() function in the C++ programming. Can anyone knows about the push_heap() function of C++ language.
Reply With Quote
  #2  
Old 05-03-2010
Member
 
Join Date: Oct 2005
Posts: 2,389
The push_heap() function in the C++

The push_heap() function of the C++ language can be used to add an element that can be defined as the end element before end into a heap that can be defined as the range of an elements that can be in between the range [strt,''end-1). If an object of the weak sequencing comparison function that can be given then it can be used in place of the "<" operator to compare an elements. The push_heap() function can be executed in logarithmic time.
Reply With Quote
  #3  
Old 05-03-2010
Member
 
Join Date: May 2008
Posts: 2,383
push_heap() function in the C++

The push_heap() function can given a heap range such as [fst,lst-1), the push_heap() function that can extends the range that can be considered a heap to the range [fst,lst) by placing the value in (lst-1) in its relevant place in it. The following can be the syntax of the push_heap() function in C++ language :
Code:
template <class RndmAcesItrtr>
  void push_heap ( RndmAcesItrtr fst, RndmAcesItrtr lst );
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #4  
Old 05-03-2010
Member
 
Join Date: Apr 2008
Posts: 1,948
Use of th push_heap() function in the C++

I can suggest you that to carefully go through the following code of lines that can demonstrates you how to use the push_heap() function in the C++ programming as follows :
Code:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main ()
 {
  int mit[] = {10,20,30,5,15};
  vector<int> z(mit,mit+5);
  vector<int>::iterator it;
  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;
}
Output:
Code:
initial max heap   : 30
max heap after pop : 20
max heap after push: 99
final sorted range : 5 10 15 20 99
Reply With Quote
  #5  
Old 05-03-2010
Member
 
Join Date: Feb 2008
Posts: 1,848
re: Use of the push_heap() function in the C++

The following can be the general syntax of the push_heap() function in the C++ language :
1. cmp : This parameters of the push_heap() function can contains an object of the comparison function that can taking two values of the similar type than those that can contained in the given range.
2. fst, lst : These parameters of the push_heap() function can contains the random access iterators to the final and starting positions of the newer heap including an element that can be pushed. The range used can be as [fst,lst).
Reply With Quote
  #6  
Old 05-03-2010
Member
 
Join Date: Jan 2008
Posts: 1,515
The push_heap() function

Here can be the one more example on the push_heap() function of the C++ language and the following program can help's you to learn the push_heap() function :
Code:
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <numeric>
template <class S>
inline void PRNTELMNTS (const S& cl, const char* otcstr="")
{
    typename S::const_iterator pos;
    std::cout << otcstr;
    for (p=cl.begin(); p!=cl.end(); ++p)
    {
        std::cout << *p << ' ';
    }
    std::cout << std::endl;
}
template <class S>
inline void INSRTELMNTS (S& cl, int fst, int lst)
{
    for (int a=fst; a<=lst; ++a) 
    {
        cl.insert(cl.end(),a);
    }
}
using namespace std;
int main()
{
    vector<int> cl;
    INSRTELMNTS(cl,3,7);
    INSRTELMNTS(cl,5,9);
    INSRTELMNTS(cl,1,4);
    PRNTELMNTS (cl, "on entry:           ");
    cl.push_back (17);
    push_heap (cl.begin(), cl.end());
    PRNTELMNTS (cl, "after push_heap():  ");
}
OUTPUT :
Code:
on entry:           3 4 5 6 7 5 6 7 8 9 1 2 3 4
after push_heap():  17 8 9 7 7 5 6 3 6 4 1 2 3 4 5
Reply With Quote
Reply

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



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Use of the push_heap() function in the C++"
Thread Thread Starter Forum Replies Last Post
c++ equivalent function to the c-function 'sprintf Dilbert Software Development 6 13-12-2011 04:03 PM
c# function equivalent to gettime function in javascript Omaar Software Development 4 10-03-2010 10:44 PM
How to pass function with parameters to another function in PHP? Linoo Software Development 5 27-02-2010 07:52 PM
How does abstract function differs from virtual function? Maddox G Software Development 5 29-01-2010 11:32 AM
Function keys don't function under windows XP GunFighter Hardware Peripherals 3 08-04-2009 11:07 PM


All times are GMT +5.5. The time now is 06:46 PM.