Question
I need this program in java. Please help me as soon as possible. Below is the details for this Question 1. Write a C++ (or
I need this program in java. Please help me as soon as possible.
Below is the details for this Question
1. Write a C++ (or Java) program for hw5_1 to conduct heap operations. Input format: This is a sample input from a user. The first line (= 5 in the example) indicates that there are five numbers in the second line (= 10, 20, 30, 40, and 70 in the example). In the program, you can assume that all numbers in the heap are unique (= 5 10 20 30 40 70 5 displayMax insert 50 insert 15 deleteMax display
CST370 Page 2 of 9 Homework 5 no duplicates). Your program should read the numbers and display if its a max heap or not. If its not a max heap, your program should construct a heap with the numbers. Thus, this is the heap built with the input data. The third line (= 5 in the example) indicates the number of commands you have to conduct to the heap. The commands include displayMax, insert (= insert a number to the heap and do the heapify to adjust the heap), deleteMax, and display (= display all nodes in the heap on the screen). For the displayMax command, your program should display 70 on the screen. After that, your program should insert 50 and 15 to the heap. This is the result after the two insert operations. For the deleteMax command, your program should delete the max (= 70) from the heap. This is the result. For the display command, your program should display the nodes in the heap (= 50 40 30 10 20 15) 70 40 30 10 20 70 40 50 10 20 30 15 50 40 30 10 20 15CST370 Page 2 of 9 Homework 5 no duplicates). Your program should read the numbers and display if its a max heap or not. If its not a max heap, your program should construct a heap with the numbers. Thus, this is the heap built with the input data. The third line (= 5 in the example) indicates the number of commands you have to conduct to the heap. The commands include displayMax, insert (= insert a number to the heap and do the heapify to adjust the heap), deleteMax, and display (= display all nodes in the heap on the screen). For the displayMax command, your program should display 70 on the screen. After that, your program should insert 50 and 15 to the heap. This is the result after the two insert operations. For the deleteMax command, your program should delete the max (= 70) from the heap. This is the result. For the display command, your program should display the nodes in the heap (= 50 40 30 10 20 15) 70 40 30 10 20 70 40 50 10 20 30 15 50 40 30 10 20 15
CST370 Page 3 of 9 Homework 5 Sample Run 0: Assume that the user typed the following lines 5 10 20 30 40 70 5 displayMax insert 50 insert 15 deleteMax display This is the correct output. For the input data, your program should display that its not a heap. Then, 70 is the current max of the heap for the command displayMax. The result (= 50 40 30 10 20 15) is the result of display command. This is NOT a heap. 70 50 40 30 10 20 15 Sample Run 1: Assume that the user typed the following lines 6 20 10 8 1 3 5 4 display deleteMax displayMax display This is the correct output. This is a heap. 20 10 8 1 3 5 10 10 5 8 1 3 Sample Run 2: Assume that the user typed the following lines 11 99 55 88 44 33 66 77 22 11 5 3 4 insert 200 display insert 100 display
CST370 Page 4 of 9 Homework 5 This is the correct output. This is a heap. 200 55 99 44 33 88 77 22 11 5 3 66 200 55 100 44 33 99 77 22 11 5 3 66 88
1. Write a C++ (or Java) program for hw5_1 to conduct heap opcrations. Input format: This is a sample input from a user. The first line ( 5 in the example) indicates that there are five numbers in the second line (10,20,30, 40 , and 70 in the example). In the program, you can assume that all numbers in the heap are unique (= cst370 Page 1 of 9 Hosurworks 5 no duplicates). Your program should read the numbers and display if it's a max heap or not. If it's not a max heap, your program should construct a heap with the numbers. Thus, this is the heap built with the input data. Sample Run 0: Assume that the user typed the following lines 5 1020304070 5 dieplayMax inyert 50 inaert 15 deleteNax diglay This is the correct output. For the input data, your program should display that it's not a heap. Then, 70 is the current max of the heap for the command "displayMax". The result (=50 4030102015) is the result of "display" command. Thisisnotaheap.70504030102015 Sample Run 1: Assume that the user typed the following lines 6 2010 g 135 4 diaplay deleteMax difplayMax diplay This is the correct outpul. Sample Run 2: Assume that the user typed the following lines The third line (= 5 in the example) indicates the number of commands you have to conduct to the heap. The commands include "displayMax", "insert" (= insert a number to the heap and do the "heapify" to adjust the heap), "deleteMax", and "display" (= display all nodes in the heap on the screen). For the "displayMax" command, your program should display "70" on the screen. After that, your program should insert " 50 " and "15" to the heap. This is the result after the two insert operations. For the "deletelMax" command, your program should delete the max(=70) from the heap. This is the result. For the "display" command, your program should display the nodes in the heap (=504030102015) cst3x Pagge 2 of 9 Homework 5Step 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