Question: I need to make a priority queue with a max heap that I already created. I am having troubles with the queue since I haven't
I need to make a priority queue with a max heap that I already created. I am having troubles with the queue since I haven't made many and have thoroughly confused myself and destroyed my code.
JAVA on BlueJ
public class MainClass{ public static void main(String args[]){ PriorityQueue priorityQueue = new PriorityQueue(4); priorityQueue.insert(new Node(0, 12)); priorityQueue.insert(new Node(1, 22)); priorityQueue.insert(new Node(2, 4)); priorityQueue.insert(new Node(3, 57)); for(int i=0; i<7; i++){ System.out.print(priorityQueue.extract().key + ""); } } }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
public class Heap{ protected Node[] heap; protected int heapsize; protected int[] location;
public Heap(){ heap = new Node[20]; } public Heap(int n){ heap = new Node[n]; } public Heap(Node[] a){ //create a heap from an array of nodes } public int parent(int i){ return ((i-1) /2); } public int right(int i){ return i*2+2; } public int left(int i){ return i*2+1; } public void heapify(int i){ int left = left(i); int right = right(i); int largest = i; if(left
class PriorityQueue extends Heap{ public PriorityQueue(int maxSize){ PriorityQueue
/////////////////////////////////////////////////////////////////////////////////////////////////////
public class Node implements Comparable
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
