Hi
I’m trying to print a 4-heap
This is my code:
public AnyType printH(AnyType t, int depth)
{
if (t != null)
{
for( int i = 1; i < depth; i++ )
System.out.print( " " );
System.out.println(t);
int a = 4 * (indexnode - 1) + 1;
if (a + 4 < array.length-1)
{
printH(array[a + 1], depth+1);
indexnode++;
printH(array[a + 2], depth+1);
indexnode++;
printH(array[a + 3], depth+1);
indexnode++;
printH(array[a + 4], depth+1);
indexnode++;
}
return t;
}
else
System.out.println("Empty heap");
return t;
}
private int indexnode = 1;
And my output:
1
Empty heap
Empty heap
Empty heap
Empty heap
2
3
4
5
6
7
8
9
10
The output is supposed to be:
(indicated with tab where there is supposed to be a tab)
1
tab 2
tab tab 6
tab tab 7
tab tab 8
tab tab 9
tab 3
tab tab 10
tab 4
tab 5
What am I doing wrong?