This here -----> http://practiceit.cs.washington.edu in the 3rd edition chapter
ID: 3678065 • Letter: T
Question
This here -----> http://practiceit.cs.washington.edu in the 3rd edition chapter 18 problem number 15
Write a method in the HeapIntPriorityQueue class called merge that accepts another HeapIntPriorityQueue as a parameter and adds all elements from the other queue into the current queue, maintaining proper heap order such that the elements will still come out in ascending order when they are removed. Your code should not modify the queue passed in as a parameter. (Recall that objects of the same class can access each other's private fields.)
------------------------------------------------------------------------------------------------------
Related Files:
(((((((((((For this problem, you are supposed to submit code that will become part of an existing Java class as described. You do not need to write the complete class, just the portion described in the problem.)))))))))))
please before send solution please check answer here
http://practiceit.cs.washington.edu/problem.jsp?category=Building+Java+Programs%2C+3rd+edition%2FBJP3+Chapter+18&problem=bjp3-18-e15-mergeHeapIntPriorityQueue
I get 3 wrong answers for this question
Explanation / Answer
public void merge(HeapIntPriorityQueue q1){
Iterator<Integer> i1 = this.iterator();
Iterator<Integer> i2 = q1.iterator();
for(;;) {
if (i2.hasNext()) {
this.add(i2.next());
}
if (!i2.hasNext()) {
break;
}
}
this.bubbleUp(this.size,false);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.