class BinaryTreeNode():
def __init__(self,value=None,left=None,right=None):
self.value=value
self.left=left
self.right=right
def Convert_(pRoot):
pLastNodeInList=None
Convert(pRoot,pLastNodeInList)
pHeadlist=pLastNodeInList
while pHeadlist is not None and pHeadlist.left is not None:
pHeadlist=pHeadlist.left
return pHeadlist
def Convert(pNode,pLastNodeInList):
if pNode is None:
return
pCurrent=pNode
if pCurrent.left is not None:
Convert(pCurrent.left,pLastNodeInList)
pCurrent.left=pLastNodeInList
if pLastNodeInList.right is not None:
pLastNodeInList.right=pCurrent
pLastNodeInList=pCurrent
if pCurrent.right is not None:
Convert(pCurrent.left,pLastNodeInList)
面试题27:二叉搜索树与双向链表
最新推荐文章于 2022-05-13 21:54:01 发布