Hi guys, I just can't figure out how to traverse trough this heap. It's a 4-heap and I'm trying to implement a toString method for it. It should return a string and must be recursive. Like pre-order traversal. I'm lost with it.
public String toString(int index,String out)
{
int child = index*4+1;
out+= (array[index] +"/n");
if (child<=currentSize-1)
{
out+=toString(child,out.concat("/t"));
}
if (child+1<=currentSize-1)
{
out+=toString(child+1,out.concat("/t"));
}
if (child+2<=currentSize-1)
{
out+=toString(child+2,out.concat("/t"));
}
if (child+3<=currentSize-1)
{
out+=toString(child+3,out.concat("/t"));
}
return out;
}