voidConvertnode (Bstreenode *root, Bstreenode * *plastnodeinlist) { if(!root)return ; if(root->Left ) {Convertnode (Root-Left , plastnodeinlist); } Root->left = *plastnodeinlist; if(*plastnodeinlist! =NULL) (*plastnodeinlist)->right =Root; *plastnodeinlist =Root; if(root->Right ) {Convertnode (Root-Right , plastnodeinlist); }}bstreenode*convert (bstreenode* root)//true = right, false = Left{ if(!root)returnRoot; Bstreenode* Plastnodeinlist =NULL; Convertnode (Root,&plastnodeinlist); while(Plastnodeinlist && plastnodeinlist->Left ) {Plastnodeinlist= plastnodeinlist->Left ; } returnplastnodeinlist;}
Enter a binary search tree and convert the two-fork search tree into a sorted doubly linked list. You cannot create any new nodes, you can only adjust the point pointers of the nodes in the tree.
Binary search tree and doubly linked list