I am running into what I believe is a recursive issue which I do not know how to resolve. I am designing a hashed array tree structure and I want to print out the "lowest level" in the hashed array tree. I have an array which keeps track of how many nodes are on each level, and I can calculate the lowest level based on this. Here is the code:
template <typename T>
ostream &operator << ( ostream &output, const HashNode<T> &node ){
if(node.stemNode == 0){
//leafnode
for(int i=0; i < node.numElements; i++){
output << "\n-------------------------------------------" << endl;
output << "This Node's Level: " << node.nodeLevel << endl;
output << "\nKey: " << node.keyArray[i] << endl;
output << "\nData: " << *(node.dataArray[i]) << endl;
}
}else if (node.stemNode == 1) {
//stem node
for(int j=0; j<5; j++){
if(node.childArray[j] != NULL){
output << *(node.childArray[j]);
}
}
}
int ctr = 0;
for(int i=8; i>=0; i--){
if(levels[i] == 0){
ctr++;
}
}
int lowest = 9-(ctr+1);
//output << "\nLowest Number of Levels: " << 9-(ctr+1) << endl;
return output << "\n\nLowest Level: " << lowest << " " << ctr2 << endl;
}
What happens is that when I print out output, the phrase "Lowest Level" will print out multiple times. I believe this occurs because I traverse my tree recursively. I tried to overcome this by just saving the "lowest level" value to a variable as shown above, but this did not solve the problem. The line continues to print multiple times. Is there a way to overcome this?