struct TreeNode {
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
void flatten(TreeNode *n, TreeNode *&pre) {
if (n == NULL) return;
if (pre != NULL) {
pre->right = n;
}
pre = n;
TreeNode *rChild = n->right;
flatten(n->left, pre);
n->left = NULL;
flatten(rChild, pre);
}
void flatten(TreeNode *root) {
TreeNode *pre = NULL;
flatten(root, pre);
}