二叉树的遍历方式_04
代码
class TreeNode {
int val;
TreeNode left, right;
}
void DFS01 (TreeNode root) {
if(root == null) {
return;
}
System.out.println(root);
if(root.left != null) {
DFS01(root.left);
}
if (root.right != null) {
DFS01(root.right);
}
}
void DFS02 (TreeNode root) {
if(root == null) {
return;
}
if(root.left != null) {
DFS02(root.left);
}
System.out.println(root);
if (root.right != null) {
DFS02(root.right);
}
}
void DFS03 (TreeNode root) {
if(root == null) {
return;
}
if(root.left != null) {
DFS03(root.left);
}
if (root.right != null) {
DFS03(root.right);
}
System.out.println(root);
}