Results 1 to 6 of 6

Thread: Use of the push_heap() function in the C++

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

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    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.

  3. #3
    Join Date
    May 2008
    Posts
    2,389

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

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

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

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

  6. #6
    Join Date
    Jan 2008
    Posts
    1,521

    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

Similar Threads

  1. c++ equivalent function to the c-function 'sprintf
    By Dilbert in forum Software Development
    Replies: 6
    Last Post: 13-12-2011, 04:03 PM
  2. c# function equivalent to gettime function in javascript
    By Omaar in forum Software Development
    Replies: 4
    Last Post: 10-03-2010, 10:44 PM
  3. Replies: 5
    Last Post: 27-02-2010, 07:52 PM
  4. How does abstract function differs from virtual function?
    By Maddox G in forum Software Development
    Replies: 5
    Last Post: 29-01-2010, 11:32 AM
  5. Function keys don't function under windows XP
    By GunFighter in forum Hardware Peripherals
    Replies: 3
    Last Post: 08-04-2009, 11:07 PM

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,714,048,989.72071 seconds with 16 queries