Write a program to invert a binary tree

Give a tree, invert it
     5
   /  \
  3    10
 / \   / \
1   4 7   8
Invert Tree
     5
   /   \
  10    3
 / \   / \
8   7 4   1

The problem can be solved using bottom up approach, where traverse down to the leaf node and start moving up. Swap the nodes while moving up.

  public TreeNode invertTree(TreeNode root) {
	if (root == null)
		return root;
	invertTree(root.left);
	invertTree(root.right);
	TreeNode temp = root.left;
	root.left = root.right;
	root.right = temp;
	return root;	
}