void inorder(Node* root,vector<int>&ans)
{
if(root==NULL)
return;
inorder(root->left,ans);
ans.push_back(root->data);
inorder(root->right,ans);
}
class Solution
{
public:
Node *bTreeToCList(Node *root)
{
//add code here.
if(root==NULL)
return NULL;
vector<int> ans;
inorder(root,ans);
Node* dummy=newNode(0);
Node* p=dummy,*pre=NULL;
for(auto num:ans)
{
p->right=newNode(num);
p=p->right;
p->left=pre;
pre=p;
}
p->right=dummy->right;
dummy->right->left=p;
return dummy->right;
}
};