Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

for JAVA Problem 2: 1. Class Node that includes the following: instance variables: int Data; String Name; A constructor that initializes the instance variables. Setter

for JAVA
image text in transcribed
image text in transcribed
Problem 2: 1. Class Node that includes the following: instance variables: int Data; String Name; A constructor that initializes the instance variables. Setter and getter methods for the instance variables. 2. Class MaxHeap that includes: The following instance variables Nodel) heapArray; int maxSize; // size of array int currentSize; // number of Nodes in heapArray A constructor that takes the maximum size allowed for the heap. The current size of the heap is set to 0, and the array of the heap is created. public boolean insert (int key, String Name) that inserts a value at the end of the heap then calls method reheapUp to apply the actual changes to the heap. private void reheapUp (int index) that applies the actual changes to the heap after insertion. Makes sure that a child node is always less than its parent. It starts at the end of the heap and moves up. public Node remove () that removes the first (root) value from the heap. It calls method reheapDown to apply the actual changes to the heap for removal. private void reheapDown(int index) applies the actual changes to the heap after remove. Makes sure that a parent node is always greater than its children. It starts at the end of the root of the heap and moves down. public boolean isEmpty that checks whether the heap is empty or not public void merge Heaps that merges heap a[] and b[] into one heap merged[] public void printHeap ( that prints the contents of the heap. Write a test application named TestHeap. In the main method, do the following: o Create a heap object. o Display a menu to the user asking for a choice to be entered. As follows: Please, choose a number from the following list: 1- Insert Node 2- Remove a Node 3- Check if Empty 4- Merge two heaps 5- Print Heap 5- Exit Your choice is: The program will perform the action selected by the user and display a proper message when necessary. o The program will repeat these actions until the user terminates the program. Problem 2: 1. Class Node that includes the following: instance variables: int Data; String Name; A constructor that initializes the instance variables. Setter and getter methods for the instance variables. 2. Class MaxHeap that includes: The following instance variables Nodel) heapArray; int maxSize; // size of array int currentSize; // number of Nodes in heapArray A constructor that takes the maximum size allowed for the heap. The current size of the heap is set to 0, and the array of the heap is created. public boolean insert (int key, String Name) that inserts a value at the end of the heap then calls method reheapUp to apply the actual changes to the heap. private void reheapUp (int index) that applies the actual changes to the heap after insertion. Makes sure that a child node is always less than its parent. It starts at the end of the heap and moves up. public Node remove () that removes the first (root) value from the heap. It calls method reheapDown to apply the actual changes to the heap for removal. private void reheapDown(int index) applies the actual changes to the heap after remove. Makes sure that a parent node is always greater than its children. It starts at the end of the root of the heap and moves down. public boolean isEmpty that checks whether the heap is empty or not public void merge Heaps that merges heap a[] and b[] into one heap merged[] public void printHeap ( that prints the contents of the heap. Write a test application named TestHeap. In the main method, do the following: o Create a heap object. o Display a menu to the user asking for a choice to be entered. As follows: Please, choose a number from the following list: 1- Insert Node 2- Remove a Node 3- Check if Empty 4- Merge two heaps 5- Print Heap 5- Exit Your choice is: The program will perform the action selected by the user and display a proper message when necessary. o The program will repeat these actions until the user terminates the program

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions