Heaps Write a Java application that implements the following three methods for a
ID: 3714231 • Letter: H
Question
Heaps Write a Java application that implements the following three methods for a heap. getGreaterEqualCnt - return a count of the number of values in the heap that are >= a given parameter value trimLessThan - remove any nodes from the heap that contain data values < a given parameter value trimHeap - called by "trimLessThan" to perform trim operations Starter code for this assignment is available on the course Web site. After the trim operation is performed, every parent node data value should still be greater than the data values of all of it's children and no parent should have a right child without a left child. However, it is possible that the heap tree may become "unbalanced" from the trim. *** Important note: You are not required to "re-balance" the heap tree after a call to trimLessThan. Hint: Use recursion for the getGreaterEqualCnt and trimLessThan methods.
Explanation / Answer
private int findGreaterEqual(HeapNodeptr,Integer data,int dataCnt)
{
if(ptr==null)return dataCnt;
if(ptr.data<data)return dataCnt;
dataCnt++;
dataCnt=findGreaterEqual(ptr.leftChild,data,dataCnt);
dataCnt=findGreaterEqual(ptr.rightChild,data,dataCnt);
return dataCnt;
}
public int getGreaterEqualCnt(Integer data)
{
return findGreaterEqual(top,data,0);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.