473,231 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

STL and heap / priority queue

Is the STL priority queue a proper implementation of a heap with siftup
algorithm etc ? How do you implement an STL priority queue (link to an
example) ? Is there a resort method, why ?
Thanks

Sep 20 '06 #1
4 10323
vf***@talktalk.net wrote:
Is the STL priority queue a proper implementation of a heap with siftup
algorithm etc ?
Yes.
How do you implement an STL priority queue (link to an
example) ?
#include <queue>

std::priority_queue<intq;
You use push() to add members,
top() to get the top element and pop() to remove the top element.

Is there a resort method, why ?
Yes, but you don't need it. It's for people implementing their own
heaps for various reasons.
Sep 20 '06 #2

Thanks red floyd, are you related to pink ? Are you back at the hotel ?

Sep 20 '06 #3
vf***@talktalk.net wrote:
Is the STL priority queue a proper implementation of a heap with siftup
algorithm etc ? How do you implement an STL priority queue (link to an
example) ? Is there a resort method, why ?
Thanks
Technically a priority queue is an abstract data type whereas a heap is
a specific data structure which *can* be used to implement a priority
queue. AFAIK, there's no requirement or guarantee that the priority
queue is implemented as a heap (though in practice you're likely to find
that it is).

There is no resort method in the priority_queue interface.
Sep 20 '06 #4
Mark P wrote:
>
There is no resort method in the priority_queue interface.

No, but there is std::make_heap(), if you want to roll your own priority
queue. Also, priority_queue is available for private inheritance (the
underlying container is a protected member).
Sep 21 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Andre Paim Lemos | last post by:
Hi, I'm having some compiler problems when I try to use make_heap(), push_heap() and pop_heap(). I am compiling my code on gcc version 3.3.1 (SuSE Linux). I am using the heap related methods to...
5
by: Dan H. | last post by:
Hello, I have implemented a C# priority queue using an ArrayList. The objects being inserted into the priority queue are being sorted by 2 fields, Time (ulong) and Priority (0-100). When I...
5
by: Ook | last post by:
I'm not sure this is technically a c++ question, maybe there is a better ng to ask, but I'll start here since I'm coding this in c++. What exactly is a max heap, and more specifically, how do you...
6
by: imutate | last post by:
How do you use std::priority_queue to store say an index type (call it intidx) and sort using another integer type (but smallest weight at the top) ? How do you pop off the top index ? I mean...
3
by: PicO | last post by:
i need some explanation about the difference between priority queue & set & heap ... as they all sort the data in ( n log n ) ... but the only i see that priority queue only can pop the top (...
4
by: jjh5030 | last post by:
This is a programming assignment. You are asked to work with pointers. Be aware that error messages are often not very helpful when your pointers point to bad locations. Therefore, reserve...
1
by: corey2024 | last post by:
i need to create a program that will implement a priorty queue for a global shipping company. the program needs to keep track of which package needs to leave the warehouse next. you can only interact...
6
by: viki | last post by:
I have vector 'vec' of integers which was made into valid heap using std::make_heap(). Then we change value of a single element vec, like: vec = new_value; Now this makes vec not a valid...
14
by: AlarV | last post by:
Hello everyone, here is my problem. I have to make a dynamic priority queue,which is a heap, and my book isn't helpful at all, so I have no clues on how to create it.. I read something like a static...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.