Convert Binary Search Tree to Sorted Doubly Linked List (Tree)
Convert a BST to a sorted circular doubly-linked list in-place. Think of the left and right pointers as synonymous to the previous and next pointers in a doubly-linked list.

A circular doubly-linked list. Think of the left and right pointers in a tree as synonymous to the previous and next pointers in a list.
The idea is using in-order traversal set previous visited node's left node points to current node, and current node's right node points to previous visited node.
How do we set head's left points to last and the last's right points to head? We just need to keep the head node and let it's left points to the current node, and current node's right points to the head node.
edge case: root node only, we need to point left and right to root itself.
分析
就是树的Inorder 加上prev cur之类的指针
recursive:这里最后的prev就是最后的node,和head串起来就行了
Last updated
Was this helpful?

