Guest User

Untitled

a guest
Apr 23rd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.43 KB | None | 0 0
  1. class Node {
  2.     char val;
  3.     Node left, right;
  4. }
  5.  
  6.  
  7. public void printLevel(Node root, int level) {
  8.     printLevel(root, level, 0);
  9. }
  10.  
  11. public void printLevel(Node root, int levelToPrint, int currLevel) {
  12.     if (currLevel == levelToPrint) {
  13.         System.out.print(root.val);
  14.     }
  15.     else {
  16.         printLevel(root.left, levelToPrint, currLevel + 1);
  17.         printLevel(root.right, levelToPrint, currLevel + 1);
  18.     }
  19. }
Add Comment
Please, Sign In to add comment