Results 1 to 5 of 5

Thread: How to use the pop_heap() in C++ coding

  1. #1
    Join Date
    Dec 2009
    Posts
    26

    How to use the pop_heap() in C++ coding

    I am the student of the Bsc-CS. I must have to submit the assignment on the functions of the C++ library in four days. I could also had the well knowledge of the functions that could be used in the C++ programming language. Even though, I could not know much more about the pop_heap() function of the C++ programming language. So, I would like to know about the pop_heap() function of the C++ programming language. I also would like to know How to use the pop_heap() in C++ coding. Reply Me!!

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    The pop_heap() in C++ coding

    The pop_heap() function can be used for an element that can be from the given heap range to pop that an element. The pop_heap() function can re-sequence an elements in the given specified range [fst,lst) in such a manner that the some place of considered a heap can be narrowed by one by deleting its highest an element. The following can be the general syntax of the pop_heap() function in the C++ :
    Code:
    template <class RndmAcsItrtr>
      void pop_heap ( RndmAcsItrtr fst, RndmAcsItrtr lst );
    Last edited by Praetor; 05-03-2010 at 05:12 PM.

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

    Use the pop_heap() in C++ coding

    The program that can be mentioned below illustrates you about how to use the pop_heap() function in the C++ language programming :
    Code:
    #include <iostream>
    #include <algorithm>
    #include <vector>
    using namespace std;
    int main () 
    {
      int mit[] = {10,20,30,5,15};
      vector<int> w(mit,mit+5);
      vector<int>::iterator it;
      make_heap (w.begin(),w.end());
      cout << "initial max heap   : " << w.front() << endl;
      pop_heap (w.begin(),w.end()); w.pop_back();
      cout << "max heap after pop : " << w.front() << endl;
      w.push_back(99); push_heap (w.begin(),w.end());
      cout << "max heap after push: " << w.front() << endl;
      sort_heap (w.begin(),w.end());
      cout << "final sorted range :";
      for (unsigned k=0; k<w.size(); k++) cout << " " << w[k];
      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

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    How to use the pop_heap() in C++ coding

    The following can be the parameters of the pop_heap() function of the C++ language :
    1. comp : This parameter of the pop_heap() function can contains an object of the comparison function that can takes two values of the similar type than those can consisted in the given specified range.
    2. fst, lst : These parameters of the pop_heap() function can contains the random-Access iterators to the final and starting positions of the heap that can be shrank by one. The range used can be as [fst,lst) that can contains all of an elements that can be between fst and lst.

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

    How to use the pop_heap()

    The pop_heap() function of the C++ language can be used to delete the highest an element that can be defined as an element at the front of the heap from the specified heap. If an object of the weak sequencing comparison function can be given then it can be used instead of the "<" operator to compare an elements. The pop_heap() function can runs in a logarithmic time. The pop_heap() function of the C++ language can be comes under the <algorithm> header files.

Similar Threads

  1. java coding
    By unikshegz in forum Software Development
    Replies: 1
    Last Post: 27-10-2010, 01:56 AM
  2. Help me to use the transform() in C++ coding
    By Tailor in forum Software Development
    Replies: 5
    Last Post: 19-02-2010, 04:17 PM
  3. Help in coding documents
    By Remedy in forum Software Development
    Replies: 5
    Last Post: 11-02-2010, 02:34 AM
  4. C++ coding faster?
    By Chandrakant81 in forum Software Development
    Replies: 3
    Last Post: 17-02-2009, 10:51 PM
  5. Problem with C coding
    By SANDESH49 in forum Software Development
    Replies: 2
    Last Post: 02-09-2008, 01:23 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,713,557,476.07955 seconds with 17 queries