473,499 Members | 1,614 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C++ priority queue with bubble-up and bubble-down?

Hi guys,

Just wondering what you'd recommend in terms of a C++ priority queue
implementation that supports bubble-up and bubble-down operations
please? std::priority_queue doesn't seem to support doing that, and I
couldn't find an alternative in Boost. I could write my own, but that
feels a little bit like reinventing the wheel, so I thought it was worth
asking first.

Cheers,
Stu
Aug 5 '08 #1
3 5201
Stuart Golodetz wrote:
Hi guys,

Just wondering what you'd recommend in terms of a C++ priority queue
implementation that supports bubble-up and bubble-down operations
please? std::priority_queue doesn't seem to support doing that, and I
couldn't find an alternative in Boost. I could write my own, but that
feels a little bit like reinventing the wheel, so I thought it was worth
asking first.

Cheers,
Stu
When I said "bubble-up" and "bubble-down", what I really meant was
increase key and decrease key (not necessarily respectively). Just to
clarify :-)

Stu
Aug 5 '08 #2
On Aug 5, 2:25*pm, Stuart Golodetz
<sgolod...@NdOiSaPlA.pMiPpLeExA.ScEomwrote:
Stuart Golodetz wrote:
Just wondering what you'd recommend in terms of a C++ priority queue
implementation that supports bubble-up and bubble-down operations
please? std::priority_queue doesn't seem to support doing that, and I
couldn't find an alternative in Boost. I could write my own, but that
feels a little bit like reinventing the wheel, so I thought it was worth
asking first.

When I said "bubble-up" and "bubble-down", what I really meant was
increase key and decrease key (not necessarily respectively). Just to
clarify :-)
Technically a PQ doesn't support bubble/key operations. You're wanting
a heap. Check out std::make_heap, std::sort_heap, and related
functions.

Cheers! --M
Aug 5 '08 #3
mlimber wrote:
On Aug 5, 2:25 pm, Stuart Golodetz
<sgolod...@NdOiSaPlA.pMiPpLeExA.ScEomwrote:
>Stuart Golodetz wrote:
>>Just wondering what you'd recommend in terms of a C++ priority queue
implementation that supports bubble-up and bubble-down operations
please? std::priority_queue doesn't seem to support doing that, and I
couldn't find an alternative in Boost. I could write my own, but that
feels a little bit like reinventing the wheel, so I thought it was worth
asking first.
When I said "bubble-up" and "bubble-down", what I really meant was
increase key and decrease key (not necessarily respectively). Just to
clarify :-)

Technically a PQ doesn't support bubble/key operations. You're wanting
a heap. Check out std::make_heap, std::sort_heap, and related
functions.

Cheers! --M
Thanks, think I may have been confusing the interface and the
implementation (since PQs are often implemented as heaps internally).
That being said, it is looking increasingly as if I'll have to cook my
own at least to some extent: I need dictionary lookup for the decrease
key/increase key operations, I don't think I can just use the simple
approach which is possible when you already have a pointer to the
element whose key you're trying to change. But I'll take a look at the
heap operations and see if I can make use of them somehow to avoid
completely reinventing things...

Cheers for the help :-)
Stu
Aug 5 '08 #4

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

Similar topics

38
5730
by: Aaron W. LaFramboise | last post by:
Hello, I understand that an easy way to make the standard std::priority_queue stable is by including an integer stamp with each node that is incremented each time a new node is pushed into the...
5
13200
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...
16
5369
by: Crirus | last post by:
hello I read somewhere about priority queue...what is that and Vb net have such class? -- Ceers, Crirus ------------------------------ If work were a good thing, the boss would take it...
4
10342
by: vfunc | last post by:
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
6
9007
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...
8
3655
by: vidishasharma | last post by:
Can somebody suggest good URL which contains code for merging of 2 or more priority queues in c#.
3
4345
by: Chris Lasher | last post by:
Hello, I am working with large graphs (~150,000 to 500,000 nodes) which I need decompose node-by-node, in order of a node's value. A node's value is determined by the sum of its edge weights....
3
7396
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 (...
1
8905
by: kieselchen | last post by:
hej, i would like to use the stl priority queue, but i occasionally have to remove random elements form the queue. is there any possibility for that? concert problem: i'd like to use priority...
3
6934
by: morris11 | last post by:
I want to implement a priority queue based on a sorted linked list. The remove operation on the priority queue should remove the item with a smallest key. Can anybody give me an idea how to do that?
0
7134
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7395
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4921
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3108
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3103
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
311
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.