|
|
@ -18,7 +18,7 @@ public class Code03_UnRecursiveTraversalBT {
|
|
|
|
System.out.print("pre-order: ");
|
|
|
|
System.out.print("pre-order: ");
|
|
|
|
if (head != null) {
|
|
|
|
if (head != null) {
|
|
|
|
Stack<Node> stack = new Stack<Node>();
|
|
|
|
Stack<Node> stack = new Stack<Node>();
|
|
|
|
stack.add(head);
|
|
|
|
stack.push(head);
|
|
|
|
while (!stack.isEmpty()) {
|
|
|
|
while (!stack.isEmpty()) {
|
|
|
|
head = stack.pop();
|
|
|
|
head = stack.pop();
|
|
|
|
System.out.print(head.value + " ");
|
|
|
|
System.out.print(head.value + " ");
|
|
|
|