Question: java problem Exception in thread main java.lang.NullPointerException at PriorityQueue.reverseHeapify(PriorityQueue.java:63) at PriorityQueue.enqueue(PriorityQueue.java:30) MY CODE: public class PriorityQueue implements Queue { private Job[] heap; private int tail;

java problem

Exception in thread "main" java.lang.NullPointerException

at PriorityQueue.reverseHeapify(PriorityQueue.java:63)

at PriorityQueue.enqueue(PriorityQueue.java:30)

MY CODE:

public class PriorityQueue implements Queue { private Job[] heap; private int tail;

/** * The constructor creates an empty array for the heap and sets the tail to 0. */ public PriorityQueue() { heap = new Job[10]; tail = 0; } public boolean isEmpty() { if (tail == 0) return true; return false; } public void enqueue(Job job) { if (tail >= heap.length) resize();

heap[tail] = job; tail++; reverseHeapify(tail); } public Job dequeue() { if(isEmpty()) return null;

Job oneHeap = heap[0]; tail--; heap[0] = heap[tail]; heap[tail]=null; heapify(0); return oneHeap; } public void clear() { heap = null; tail = 0; } private void resize() { Job[]newHeap = new Job[tail*2]; for(int i =0;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!