【 题目】
输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表。要求不能创建任何新的结点,只能调整树中结点指针的指向。
【代码】
#include<iostream>
//#include<vector>
#include<stack>
#include<algorithm>
//#include<stack>
#include<queue>
using namespace std;
struct BinaryTreeNode
{
int value;
BinaryTreeNode* left;
BinaryTreeNode* rigth;
};
void convertNode(BinaryTreeNode*node, BinaryTreeNode**last_in_list)
{
if (node ==NULL)
{
return;
}
BinaryTreeNode* current = node;
if (current->left)
{
convertNode(current->left, last_in_list);
}
current->left = *last_in_list;
if (*last_in_list)
{
(*last_in_list)->rigth = current;
}
*last_in_list = current;
if (current->rigth)
{
convertNode(current->rigth, last_in_list);
}
}
BinaryTreeNode* Convert(BinaryTreeNode*root)
{
BinaryTreeNode* last_in_list = NULL;
convertNode(root, &last_in_list);
BinaryTreeNode* head_in_list = last_in_list;
while ( head_in_list->left)
{
head_in_list = head_in_list->left;
}
return head_in_list;
}
int main()
{
return 0;
}
/****
***/