Have the PriorityQueue class you created for Seminar #3 implement the Iterable i
ID: 3576273 • Letter: H
Question
Have the PriorityQueue class you created for Seminar #3 implement the Iterable interface (which means it provides an iterator( ) method that returns an iterator). The iterator that the PriorityQueue will provide should be defined by a private inner class that implements the Iterator interface (which means it provides definitions for hasNext( ) and next( ). You do NOT need to provide a definition for the remove method. Create a driver program that tests the new PriorityQueue class. Use the for-each loop to display the patients in the queue. Then use a hasNext( ) loop, and the next( ) method, to display the patients in the queue once again.(Data Structure Java Question)
Explanation / Answer
import java.util.Scanner;
/** category Task **/
class Task
creator **/
public Task(String job, int priority)
/** toString() **/
public String toString()
come "Job Name : "+ job +" Priority : "+ priority;
}
}
/** category PriorityQueue **/
class PriorityQueue
personal Task[] heap;
personal int heapSize, capacity;
/** builder **/
public PriorityQueue(int capacity)
capability + 1;
heap = new Task[this.capacity];
heapSize = 0;
}
/** perform to clear **/
public void clear()
/** perform to see if empty **/
public mathematician isEmpty()
come heapSize == 0;
}
/** perform to see if full **/
public mathematician isFull()
come heapSize == capability - 1;
}
/** perform to induce Size **/
public int size()
come heapSize;
}
/** perform to insert task **/
public void insert(String job, int priority)
whereas (pos != one && newJob.priority > heap[pos/2].priority)
heap[pos] = newJob;
}
/** perform to get rid of task **/
public Task remove()
kid *= 2;
}
heap[parent] = temp;
come back item;
}
}
/** category PriorityQueueTest **/
public category PriorityQueueTest
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.