Mirror Tree
Page 1 of 1
Mirror Tree
public static void getMirror(BTreeNode root) {
if (root == null) {
return;
}
BTreeNode temp = root.left;
root.left = root.right;
root.right = temp;
getMirror(root.left);
getMirror(root.right);
}
public static void main(String[] args) {
BTreeNode root = new BTreeNode(1);
root.left = new BTreeNode(2);
root.left.left = new BTreeNode(3);
root.right = new BTreeNode(4);
getMirror(root);
}
if (root == null) {
return;
}
BTreeNode temp = root.left;
root.left = root.right;
root.right = temp;
getMirror(root.left);
getMirror(root.right);
}
public static void main(String[] args) {
BTreeNode root = new BTreeNode(1);
root.left = new BTreeNode(2);
root.left.left = new BTreeNode(3);
root.right = new BTreeNode(4);
getMirror(root);
}
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|