Java Reference
In-Depth Information
public
MaxHeap(
int
initialCapacity)
{
// the cast is safe because the new array contains all null entries
@SuppressWarnings("unchecked")
T[] tempHeap = (T[])
new
Comparable[initialCapacity + 1];
heap = tempHeap;
lastIndex = 0;
}
// end constructor
public void
add(T newEntry)
{
< See Segment 26.8. >
}
// end add
public
T removeMax()
{
< See Segment 26.12. >
}
// end removeMax
public
T getMax()
{
T root =
null
;
if
(!isEmpty())
root = heap[1];
return
root;
}
// end getMax
public boolean
isEmpty()
{
return
lastIndex < 1;
}
// end isEmpty
public int
getSize()
{
return
lastIndex;
}
// end getSize
public void
clear()
{
for
(; lastIndex > -1; lastIndex--)
heap[lastIndex] =
null
;
lastIndex = 0;
}
// end clear
< Private methods >
. . .
}
// end MaxHeap