#include "iostream"
using namespace std;
struct BinaryTreeNode{
int data;
BinaryTreeNode *left;
BinaryTreeNode *right;
};
BinaryTreeNode *Convert(BinaryTreeNode *pRoot)
{
BinaryTreeNode *pLastNodeInList = NULL;
ConvertNode(pRoot, &pLastNodeInList);
BinaryTreeNode *pHeadOfList = pLastNodeInList;
while (pLastNodeInList!=NULL&&pHeadOfList->left!=NULL)
{
pHeadOfList = pHeadOfList->left;
}
return pHeadOfList;
}
void ConvertNode(BinaryTreeNode *pNode,BinaryTreeNode **pLastNodeInList)
{
if (pNode == NULL)
return;
BinaryTreeNode *pCurrent = pNode;
if (pCurrent->left != NULL)
ConvertNode(pCurrent->left, pLastNodeInList);
pCurrent->left = *pLastNodeInList;
if (*pLastNodeInList != NULL)
(*pLastNodeInList)->right = pCurrent;
*pLastNodeInList = pCurrent;
if (pCurrent->right != NULL)
ConvertNode(pCurrent->right, pLastNodeInList);
}
int main()
{
system("pause");
return 0;
}
剑指offer面试题27:二叉搜索树和双向链表
最新推荐文章于 2024-06-02 16:53:30 发布