Solved

Posted on 2011-04-22

I am new to programming and my teacher wants us to implement a priority queue using heap with 3 arrays. instance variables (data[], priority[],entered[]). How would I go about doing this? I only need an add and remove method.

5 Comments

example here: http://www.vias.org/javacourse/chap16_07.html

This can get a bit messy, so be careful. Notice that to get the value of the

priority [ entered[m] ]

What you have is a binary heap where each element in the heap has up to two children. When you add a node to your PQ, you insert it at the end of the heap array, and then let it sift up by consecutive comparisons.

If the index of the element you are considering is

Right_idx = 2 * idx + 1

The

http://en.wikipedia.org/wi

heap

3 arrays named data[], priority[], and entered[]

In http:#35464813 are definitions and relationships of these three arrays. Also, since the heap is to be implemented as an array, this post also provides the parent/child index relationships for the heap. The Title | # Comments | Views | Activity |
---|---|---|---|

What is the proper way to create a script with new Select in Relic Synthetics? | 1 | 36 | |

Issues installing SSL certificate into Apache Tomcat | 3 | 50 | |

wordlen challenge | 3 | 30 | |

Microsoft C++ code failing in executable that worked | 9 | 16 |

Join the community of 500,000 technology professionals and ask your questions.

Connect with top rated Experts

**16** Experts available now in Live!