/*
struct TreeNode {
	int val;
	struct TreeNode *left;
	struct TreeNode *right;
	TreeNode(int x) :
			val(x), left(NULL), right(NULL) {
	}
};*/
class Solution {
public:
	void answer(TreeNode*root,vector <int> &ans)
	{
		if(root)
		{
			answer(root->left,ans);
			ans.push_back(root->val);
			answer(root->right,ans);
		}
	}
    TreeNode* Convert(TreeNode* pRootOfTree) 
	{
        vector <int> ans;
		answer(pRootOfTree,ans);
		int i=0;
		int len=ans.size();
		if(len==0)
		{
			return NULL;
		}
		else 
		{
			TreeNode*ans1=NULL;
			TreeNode*t=NULL;
			ans1=t=new TreeNode(ans[0]);
			for(i=1;i<len;i++)
			{
				t->right=new TreeNode(ans[i]);
				TreeNode*m=t;
				t=t->right;
				t->left=m;
			}
			ans1->left=NULL;
			t->right=NULL;
			return ans1;
		}
		return NULL;
    }
};