subject

This is an in-place heap-tree and I got some problem with finish the methods. I hope you could help me to finish it or just write a new one. The program includes insert() and remove()Please try to insert(5, A), insert(4, B), insert(7, F), insert(1, D), remove(Min) and show the result by screenshot. public class HeapTree {private int[] data;private int heapSize;public BinaryMinHeap(int size) {data = new int[size];heapSize = 0;}public int getMinimum() {if (isEmpty())throw new HeapException("Heap is empty");elsereturn data[0];}public boolean isEmpty() {return (heapSize == 0);}…private int getLeftChildIndex(int nodeIndex) {return 2 * nodeIndex + 1;}private int getRightChildIndex(int nodeIndex) {return 2 * nodeIndex + 2;}private int getParentIndex(int nodeIndex) {return (nodeIndex - 1) / 2;}public class HeapException extends RuntimeException {public HeapException(String message) {super(message);} public void removeMin() {if (isEmpty())throw new HeapException("Heap is empty");else {data[0] = data[heapSize - 1];heapSize--;if (heapSize > 0)siftDown(0);}}public void insert(int value) {if (heapSize == data. length)throw new HeapException("Heap's underlying storage is overflow");else {heapSize++;data[heapSize - 1] = value;siftUp(heapSize - 1);}}private void siftDown(int nodeIndex) {int leftChildIndex, rightChildIndex, minIndex, tmp;leftChildIndex = getLeftChildIndex(nodeIndex);rightC hildIndex = getRightChildIndex(nodeIndex);if (rightChildIndex >= heapSize) {if (leftChildIndex >= heapSize)return;elseminIndex = leftChildIndex;} else {if (data[leftChildIndex] <= data[rightChildIndex])minIndex = leftChildIndex;elseminIndex = rightChildIndex;}if (data[nodeIndex] > data[minIndex]) {tmp = data[minIndex];data[minIndex] = data[nodeIndex];data[nodeIndex] = tmp;siftDown(minIndex);}}}

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 18:40
Mariah was working on a multimedia presentation that included both video and audio files. the file was huge, and she wanted to send it to her coworker in another office. she needed to reduce the size of the file so that it could be transmitted faster. the utility she used to do this was
Answers: 2
question
Computers and Technology, 22.06.2019 21:30
The salespeople at hyperactive media sales all use laptop computers so they can take data with them on the road. you are a salesperson for superduper lightspeed computers talking to hyperactive media sales about upgrading the laptops to windows 10. explain how network location awareness in windows 10 would make the laptops more secure.
Answers: 3
question
Computers and Technology, 23.06.2019 02:00
Which demographic challenge is europe currently experiencing? a. an aging and decreasing population b. a baby boomc. an unequal distribution between males and females d. a large group of teenagers moving through the school system(i chose a but i'm unsure)
Answers: 1
question
Computers and Technology, 23.06.2019 18:50
Ais a picture icon that is a direct link to a file or folder
Answers: 1
You know the right answer?
This is an in-place heap-tree and I got some problem with finish the methods. I hope you could help...
Questions
question
Physics, 30.08.2019 17:30
Questions on the website: 13722367