Advertisement
lobaev

Untitled

Feb 24th, 2020
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. private static void dfs(Node node, LinkedList<Character> word) {
  2. word.add(node.c);
  3. if (node.left == null && node.right == null) {
  4. printWord(word);
  5. } else {
  6. if (node.left != null) {
  7. dfs(node.left, word);
  8. }
  9. if (node.right != null) {
  10. dfs(node.right, word);
  11. }
  12. }
  13. word.removeLast();
  14. }
  15.  
  16. private static void printWord(LinkedList<Character> word) {
  17. word.forEach(System.out::print);
  18. System.out.println();
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement