递归版本:
public static void reversePre(Node head){
if (head == null)
return;
System.out.print(head.value+",");
reversePre(head.left);
reversePre(head.right);
}
非递归版本:
public static void unReversePre(Node head){
if (head != null){
Stack<Node> stack = new Stack<>();
stack.push(head);
while (!stack.isEmpty()){
head = stack.pop();
System.out.print(head.value+",");
if (head.right != null)
stack.push(head.right);
if (head.left != null)
stack.push(head.left);
}
}
}