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 04:30
What kind of software users of all skill levels create web pages that include graphics, video, audio, animation, and other special effects? website authoring website software website publishing website editing
Answers: 1
question
Computers and Technology, 22.06.2019 11:30
Andrina writes letters that are regularly sent to hundreds of her company’s customers. because of this, she would like for the mail merge command to be in her quick access toolbar, and she wants it to be the first button on the left. what should andrina do to place the mail merge button there?
Answers: 1
question
Computers and Technology, 22.06.2019 14:10
Dean wants a quick way to look up staff members by their staff id. in cell q3, nest the existing vlookup function in an iferror function. if the vlookup function returns an error result, the text “invalid staff id” should be displayed by the formula. (hint: you can test that this formula is working by changing the value in cell q2 to 0, but remember to set the value of cell q2 back to 1036 when the testing is complete.)
Answers: 3
question
Computers and Technology, 23.06.2019 05:00
Jason works as an accountant in a department store. he needs to keep a daily record of all the invoices issued by the store. which file naming convention would him the most?
Answers: 2
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
History, 02.01.2020 06:31
question
History, 02.01.2020 06:31
question
Mathematics, 02.01.2020 06:31
question
Mathematics, 02.01.2020 06:31
question
Mathematics, 02.01.2020 06:31
Questions on the website: 13722367