/**
* Created by WHZ on 2017/4/5.
*/
public class offer27 {
private class BinaryTreeNode{
int val;
BinaryTreeNode left;
BinaryTreeNode right;
}
BinaryTreeNode Convert(BinaryTreeNode pRootOfTree){
BinaryTreeNode pLastNodeInList = ConvertNode(pRootOfTree);
BinaryTreeNode pHeadOfList = pLastNodeInList;
while(pHeadOfList!=null&&pHeadOfList.left!=null)
pHeadOfList = pHeadOfList.left;
return pHeadOfList;
}
private BinaryTreeNode ConvertNode(BinaryTreeNode pNode) {
if(pNode == null)
return null;
BinaryTreeNode pLastNodeInList = null;
if(pNode.left !=null)
pLastNodeInList = ConvertNode(pNode.left);
pNode.left = pLastNodeInList;
if(pLastNodeInList !=null)
pLastNodeInList.right = pNode;
pLastNodeInList = pNode;
if(pNode.right!=null)
pLastNodeInList = ConvertNode(pNode.right);
return pLastNodeInList;
}
}
剑指offer27:二叉搜索树与双向链表
最新推荐文章于 2024-06-02 16:53:30 发布