class Solution {

public:

void flatten(TreeNode* root) {

traversal(root);

}

TreeNode* traversal(TreeNode* root){

if(!root)

return NULL;

TreeNode* left = traversal(root->left);

TreeNode* right = traversal(root->right);

if(left){

TreeNode* tmp = root->right;

root->right = root->left;

left->right = tmp;

root->left = NULL;

}

if(right)

return right;

else if(left)

return left;

else

return root;

}

};