Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. public static void printout(int[] tree, int index)
  2. {
  3. //if the left node is 0, print value in parent node
  4. if (tree[index*2] == 0) {
  5. System.out.println(tree[index]);
  6.  
  7. //if the right node is 0, return to previous node
  8. if(tree[index*2+1] == 0) {
  9. System.out.println(tree[index/2]);
  10.  
  11. //if the right node is not 0, go to next right node
  12. } else {
  13. printout(tree, index*2+1);
  14. }
  15.  
  16. //if left node is not 0, go to next left node
  17. } else {
  18. printout(tree, index*2);
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement