void help(Node* root, Node* &head){
if(!root) return;
Node *left = root->left, *right = root->right;
help(left,head);
if(!pre){
pre = root;
head = root;
}else{
root->left = pre;
pre->right = root;
}
root->right = head;
head->left = root;
pre = root;
help(right,head);
return;
}
Node *bTreeToCList(Node *root)
{
if(!root) return root;
Node* head = NULL;
help(root,head);
return head;
}
This code is failing on some test cases. Please explain y.