Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The goal of the homework is to implement a priority queue as a BST adapter. This requires: 1. The creation of a method: removeMin for
The goal of the homework is to implement a priority queue as a BST adapter. This requires: 1. The creation of a method: removeMin for the BST class 2. The modification of the usual insert method in the BST class to allow for insertion of duplicate data. The following program is missing its insert and removeMin methods. The main purpose of the project is to supply these methods. You should also alter the class E00000000 to match your ID number and make it print your name and ID number as the first line of output. The main program is designed to operate a PQsort function on random integer data. ********************************************************************/ import java.util.ArrayList; import java.util.Iterator; import java.util.Random; import class22.BST; import class13.BNode; import class17.PriorityQueue; class BSTPQ> extends BST implements PriorityQueue { public void insert(K x) throws Exception { // TODO add this code return; } public K removeMin() throws Exception { // TODO add this code return null; } } // ---- main program to test priority queue methods class E00000000 { public static Iterator PQsort(Iterator x) throws Exception { PriorityQueue q = new BSTPQ (); while (x.hasNext()) q.insert(x.next()); ArrayList temp = new ArrayList<>(); try { while (true) temp.add(q.removeMin()); } catch (Exception e) {} return temp.iterator(); } public static void main(String args[]) throws Exception { Random r = new Random(); ArrayList v = new ArrayList<>(); for (int i = 0; i < 20; i++) v.add(r.nextInt(30)); System.out.print("Unsorted: "); for (Integer x:v) System.out.print("" + x + " "); System.out.print(" Sorted: "); Iterator sorted = PQsort(v.iterator()); while (sorted.hasNext()) System.out.print("" + sorted.next() + " "); System.out.println(); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started