Computers and Technology
Computers and Technology, 03.09.2020 03:01, cocoapop

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);}}}

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 11:30, genyjoannerubiera
What does a cascading style sheet resolve a conflict over rules for an element? a. the rule affecting the most content wins b. the rule affecting the most content loses c. the rule with the most specific selector loses d. the rule with the most specific selector wins
Answers: 2
image
Computers and Technology, 22.06.2019 19:10, kaiya789
10. when you create a pivottable, you need to specify where to find the data for the pivottable. is it true
Answers: 2
image
Computers and Technology, 23.06.2019 16:30, azainababbas
20 points archie wants to use a reflector as he photographs a newlywed couple. what would he consider in his choice? a. shadow and sunny b. homemade and professional c. lamps and boards d. incident and reflected e. neutral density and enhancement
Answers: 3
image
Computers and Technology, 23.06.2019 18:40, brooklyn4932
How does is make you feel when you're kind to others? what are some opportunities in your life to be more kind to your friends and loved ones? imagine a world where kindness has be outlawed. how would people act differently? would your day-to-day life change significantly? why or why not?
Answers: 2
Do you know the correct answer?
This is an in-place heap-tree and I got some problem with finish the methods. I hope you could help...

Questions in other subjects:

Konu
History, 14.10.2019 06:30
Konu
English, 14.10.2019 06:30
Konu
Mathematics, 14.10.2019 06:30