Question: I have to make a priority class using a heap class I already have built. I am having all the issues with the priority queue

I have to make a priority class using a heap class I already have built. I am having all the issues with the priority queue since I havent made that many. I also have a class for Node but again unsure about.

class PriorityQueue extends Heap{ public PriorityQueue(int maxSize){ Heap priorityQueue = new Heap(maxSize); } public void insert(Node newNode){ } public Node extract(){ } public void changeKey(int i, int k){ } }

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

public class Node implements Comparable{ public int ID; public int key; public Node(int ID, int key){ } @Override public int compareTo(Node node2){ return o.ID > node2.ID ? 1:-1; } }

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

public class Heap{ protected Node[] heapArray; protected int heapsize; protected int[] loaction;

public Heap(){ heapArray = new int[20]; } public Heap(int n){ heapArray = new int[n]; } public int right(int i){ return i*2+2; } public int left(int i){ return i*2+1; } public void maxHeapify(int i){ int left = left(i); int right = right(i); int largest = i; if(leftheapArray[largest]){ largest = left; } if(rightheapArray[largest]){ largest = right; } if(largest!=i){ heapArray[i] = heapArray[i] - heapArray[largest]; heapArray[largest]= heapArray[i] + heapArray[largest]; heapArray[i]= heapArray[largest] - heapArray[i]; maxHeapify(largest); } if(significant != i){ Node temp = heap[i]; heap[i] = heap[significant]; heap[significant] = temp; location[heap[significant].ID] = significant; location[heap[i].ID] = i; heapify(significant); } } public void buildMaxHeap(){ for(int i=heapsize/2-1; i>=0; i--){ maxHeapify(i); } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!