Binary Tree Upside Down
Page 1 of 1
Binary Tree Upside Down
public BTreeNode UpsideDownBinaryTree(BTreeNode root) {
if (root == null)
return null;
BTreeNode parent = root, left = root.left, right = root.right;
if (left != null) {
BTreeNode ret = UpsideDownBinaryTree(left);
left.left = right;
left.right = parent;
return ret;
}
return root;
}
if (root == null)
return null;
BTreeNode parent = root, left = root.left, right = root.right;
if (left != null) {
BTreeNode ret = UpsideDownBinaryTree(left);
left.left = right;
left.right = parent;
return ret;
}
return root;
}
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|