二叉搜索树与双向链表
思路:
左指针指向左子树的最大值,右指针指向右子树的最小值。
struct node{
int value;
node* left;
node* right;
}
node* convert(node* root){
node* pLast = NULL;
convertNode(root,&pLast);
node* head = pLast;
while(head->left != NULL && head != NULL){
head = head->left;
}
return head;
}
void convertNode(node* root,node** pLast){
if(root == NULL)return;
node* pCurrnet = root;
if(pCurrnet->left){
convertNode(pCurrnet->let,pLast);
}
p->left = *pLast;
if(*pLast != NULL){
(*pLast)->right = pCurrnet;
}
*pLast = pCurrnet;
if(pCurrnet->right) convertNode(pCurrnet->right,pLast);
}