# Merging two Priority queues (arrayList and Linked List)

Page 1 of 1

## 1 Replies - 5794 Views - Last Post: 23 April 2012 - 06:40 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=276384&amp;s=d820369b35b502f02f58b956007ba982&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 thePhantom

Reputation: -1
• Posts: 63
• Joined: 28-April 10

# Merging two Priority queues (arrayList and Linked List)

Posted 23 April 2012 - 03:22 AM

So my assignment required that we create an arrayList priority queue of an unsorted array (data was taken from a text file) and print out the first 50 values, in order of priority. Then we had to do this using a linked list also. The part that I'm confused about, is how to go about merging the two Priority Queues, to form a single heap, and creating a new one that is the combination of the two.

According to my knowledge, I know that you could actually create two binary heaps to store the elements from the unsorted arrayList and the linked list. Creating an array that is a concatenation of the first heap's array and the second's heaps array... Getting an array-backed binary tree. Then to iteratively heap sort all sub-heaps progressively from the leaves nodes to the root node.

My problem is, that I'm having trouble putting this method into code, and was wondering if someone could perhaps guide me on an easier way to do this, or recommend any tutorials I can go through?

Is This A Good Question/Topic? 0

## Replies To: Merging two Priority queues (arrayList and Linked List)

### #2 g00se

• D.I.C Lover

Reputation: 3516
• Posts: 15,913
• Joined: 20-September 08

## Re: Merging two Priority queues (arrayList and Linked List)

Posted 23 April 2012 - 06:40 AM

Look at the docs http://docs.oracle.c...orityQueue.html
to begin with