Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static void dfs(Node node, LinkedList<Character> word) {
- word.add(node.c);
- if (node.left == null && node.right == null) {
- printWord(word);
- } else {
- if (node.left != null) {
- dfs(node.left, word);
- }
- if (node.right != null) {
- dfs(node.right, word);
- }
- }
- word.removeLast();
- }
- private static void printWord(LinkedList<Character> word) {
- word.forEach(System.out::print);
- System.out.println();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement