Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void printout(int[] tree, int index)
- {
- //if the left node is 0, print value in parent node
- if (tree[index*2] == 0) {
- System.out.println(tree[index]);
- //if the right node is 0, return to previous node
- if(tree[index*2+1] == 0) {
- System.out.println(tree[index/2]);
- //if the right node is not 0, go to next right node
- } else {
- printout(tree, index*2+1);
- }
- //if left node is not 0, go to next left node
- } else {
- printout(tree, index*2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement