题目描述
输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表。要求不能创建任何新的结点,只能调整树中结点指针的指向。
TreeNode* up = NULL;
TreeNode* head = NULL;
void create_node(TreeNode* &node)
{
if(up == NULL)
{
node->left = NULL;
head = node;
up = node;
return;
}
up->right = node;
node->left = up;
up = node;
}
public:
TreeNode* Convert(TreeNode* pRootOfTree)
{
if(pRootOfTree == NULL) return NULL;
Convert(pRootOfTree->left);
create_node(pRootOfTree);
Convert(pRootOfTree->right);
return head;
}