Sunday, September 9, 2012

Mirror a Binary Tree

Following algorithm would create a mirror of a Tree


 void mirror(TreeNode* root) { 
   if (root == NULL ) 
     return; 
  
   TreeNode* temp = root->left; 
   root->left = root->right; 
   root->right = temp; 
   mirror(root->left); 
   mirror(root->right); 
 } 

No comments:

Post a Comment