Before seeing the data structure of the book.
Assume that node is the root node of the tree, variable, then simply print it.
- Preorder traversal
Node{
Node left;
Node right;
Object val;
}
public void travel(Node root){
if(root!=null){
System.out.println(root.val)
travel(root.left);
travel(root.right);
}
}
- Preorder
Node{
Node left;
Node right;
Object val;
}
public void travel(Node root){
if(root!=null){
travel(root.left);
System.out.println(root.val);
travel(root.right);
}
}
- Postorder
Node{
Node left;
Node right;
Object val;
}
public void travel(Node root){
if(root!=null){
travel(root.left);
travel(root.right);
System.out.println(root.val);
}
}
A closer look at the top is to the preamble, in that the intermediate sequence, the sequence is later. Such a thought, instantly clear.