Heap

Heap Function

 

struct comparator
{
    bool operator()(int a, int b)
    {
        return a > b;
    }
};

priority_queue<int, vector<int>, comp> minHeap;

 minHeap.push(12);
    minHeap.push(8);
    minHeap.push(15);

  while (!minHeap.empty())
    {
        cout<<minHeap.top()<<" ";
        minHeap.pop();
    }

 

 

priority_queue <int> pq;

    pq.push(5);
    pq.push(1);
    pq.push(10);

while (pq.empty() == false)
    {
        cout << pq.top() << " ";
        pq.pop();
    }

 

0 0 votes
Article Rating
Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
trackback
1 year ago

[…] Data structure :vectorstringstackqueuemapheapset […]

error

Enjoy this blog? Please spread the word :)

1
0
Would love your thoughts, please comment.x
()
x