private void print(Stack<Node> stack, Node n) { if (n.isLeaf()) { assert n.value != null; for (Node node : stack) { System.out.print(node.key + "->"); } System.out.print(n.value); System.out.println(); return; } for (Map.Entry<Character, Node> e : n.children.entrySet()) { stack.push(e.getValue()); print(stack, e.getValue()); stack.pop(); } }
public void printAll() { Stack<Node> stack = new Stack<Node>(); stack.push(root); print(stack, root); }