严氏北美IT公司面试真题汇总和解答论坛
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Mirror Tree

Go down

Mirror Tree Empty Mirror Tree

Post by Admin Sat Oct 21, 2017 4:14 pm

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);
}

Admin
Admin

Posts : 124
Join date : 2017-10-21

https://csinterviewquestions.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum