Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The instructions are on the top of the code. Code in JAVA instructions: 1)throughout the code, there will be TODO task to complete (8 TODO

image text in transcribedimage text in transcribedimage text in transcribed

The instructions are on the top of the code. Code in JAVA

instructions: 1)throughout the code, there will be TODO task to complete (8 TODO task)

2) if needed, create helper and heapify methods

3) lastly, test what you added by added test cases in the driver (located at the bottom of the code)

3Complete the following class with given prototype/header of a priority heap Look for the TODO tasks and complete them You may need to create a few more helper methods and heapify methods 6 | + add more ?es? cases ?lto the driver to test your code 9 import java.util.*; 10 11 public class Qlleap{ 12 13 /** a simple nested class to represent the key-value pair */ class Ttem 15 16 public K key; public V value; public Item (K key, V valuc) 18 19 20 21 this.keykey; this.valuevalue public String toString ) return "key:" + this.key "nValue:"+ this.value; 23 24 25 26 27 28 29 30 private int capacity; //the maximum heap before resize is needed //end of nested class //attributes private final int DEFAULT CAPACITY private int count.; 15; private ArrayT,ist > st.orage;//array used to store the items 32 //constructors public QHeap t /ew heap with default size 34 35 36 37 38 39 40 this.count0; /o item in the storage yet this. capacity = DEFAULT-CAPACITY; //create the storage this. storage = new ArrayList >(DEFAULT-CAPACITY) ; /**create a heap with a specific size / public QHeap (int requestsize) ( 42 4 3 this.count -0; /o item in the storage yet this.capacity requestSize; this.storagenew ArrayList >(this.capacity);//create the storage 4 5 4 6 4 7 48 copy constructor - copy the content of the given heap into a new one */ public QlHeap (Olleap given) 50 51 52 53 54 //TODO: copy the data of the given heap to the new heap 56 57 58 //methods / merge the given heap into this one / public int merge (QHeap second) //TODO: merge the heap here 3Complete the following class with given prototype/header of a priority heap Look for the TODO tasks and complete them You may need to create a few more helper methods and heapify methods 6 | + add more ?es? cases ?lto the driver to test your code 9 import java.util.*; 10 11 public class Qlleap{ 12 13 /** a simple nested class to represent the key-value pair */ class Ttem 15 16 public K key; public V value; public Item (K key, V valuc) 18 19 20 21 this.keykey; this.valuevalue public String toString ) return "key:" + this.key "nValue:"+ this.value; 23 24 25 26 27 28 29 30 private int capacity; //the maximum heap before resize is needed //end of nested class //attributes private final int DEFAULT CAPACITY private int count.; 15; private ArrayT,ist > st.orage;//array used to store the items 32 //constructors public QHeap t /ew heap with default size 34 35 36 37 38 39 40 this.count0; /o item in the storage yet this. capacity = DEFAULT-CAPACITY; //create the storage this. storage = new ArrayList >(DEFAULT-CAPACITY) ; /**create a heap with a specific size / public QHeap (int requestsize) ( 42 4 3 this.count -0; /o item in the storage yet this.capacity requestSize; this.storagenew ArrayList >(this.capacity);//create the storage 4 5 4 6 4 7 48 copy constructor - copy the content of the given heap into a new one */ public QlHeap (Olleap given) 50 51 52 53 54 //TODO: copy the data of the given heap to the new heap 56 57 58 //methods / merge the given heap into this one / public int merge (QHeap second) //TODO: merge the heap here

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Solaris 11.2 System Administration (oracle Press)

Authors: Harry Foxwell

1st Edition

007184421X, 9780071844215

More Books

Students also viewed these Databases questions