private void WriteBranch (int index, int depth, System.Text.StringBuilder text) {
text.Append ("\n");
for (int i=0;i<depth;i++) {
text.Append (" ");
}
text.Append (binaryHeap[index].f);
if (index > 1) {
int parentIndex = index / 2;
if (binaryHeap[index].f < binaryHeap[parentIndex].f) {
text.Append (" !!!");
}
}
int p2 = index * 2;
if ((p2 + 1) <= numberOfItems) {
// Both children exist
WriteBranch (p2,depth+1,text);
WriteBranch (p2+1,depth+1,text);
} else if (p2 <= numberOfItems) {
// Only one child exists
WriteBranch (p2,depth+1,text);
}
}