Question: 1. Implement the Max Priority Queue operations Your program should use an array. Programming language must be Java. 2. The following operations should be implemented:

1. Implement the Max Priority Queue operations Your program should use an array. Programming language must be Java.

2. The following operations should be implemented:

INSERT.(S, x) inserts the element x into the set S, MAXIMUM(S) returns the element of S with the largest key. EXTRACT-MAX(S) removes and returns the element of S with the largest key. INCREASE-KEY(S, x, k) increases the value of element xs key to the new value k, which is assumed to be at least as large as xs current key value.

3. Your program must be able to support up to 10 integers. It would take in those integers (separated by spaces), build a max heap, then based on the operation chosen above, will perform the operation on the max heap and output per the example provided below. 4. For the program inputs, you can assume the index starts at 0. 5.The inputs to your program must be done via the console. 6. You should also have your tester in the MaxPriorityQueue.java file. In other words, both your class and tester should be in the same file. 7. Your algorithm should also be able to support just one element as your input, as well as duplicates. 8. The Increase Key operation should output an error in the console if the new key is less than the old key. 9. Extract Max should output an error if there are no integers to extract (in case of empty heap).

10. Example (inputs are bolded)

Here is the Example input and output:

Input an array of integers separated by spaces: 5 10 8 13 2 17 12 Outputted Max Heap: 17 13 12 10 2 8 5 Choose from the following options: 1. Insert 2. Maximum 3. Extract-Max 4. Increase-Key 5. Exit 1 Input the integer you want inserted: 14 Outputted Max Heap: 17 13 14 10 2 8 12 5 Choose from the following options: 1. Insert 2. Maximum 3. Extract-Max 4. Increase-Key 5. Exit 2 Maximum value is: 17 Choose from the following options: 1. Insert 2. Maximum 3. Extract-Max 4. Increase-Key 5. Exit 3 Maximum value is: 17 Outputted Max Heap: 14 13 12 10 2 8 5 Choose from the following options: 1. Insert 2. Maximum3. Extract-Max 4. Increase-Key 5. Exit 4 Input the index of the node you want to increase: 3 Input the new value: 6 ERROR: new key is smaller than current key Choose from the following options: 1. Insert 2. Maximum 3. Extract-Max 4. Increase-Key 5. Exit 4 Input the index of the node you want to increase: 3 Input the new value: 18 Outputted Max Heap: 18 14 12 13 2 8 5 Choose from the following options: 1. Insert 2. Maximum 3. Extract-Max 4. Increase-Key 5. Exit 5

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!