eBSTreeNodeCo
vertNodeBSTreeNodepNodeboolasRightifpNoderetur
NULLBSTreeNodepLeftNULLBSTreeNodepRightNULLCo
verttheleftsubtreeifpNodem_pLeftpLeftCo
vertNodepNodem_pLeftfalseCo
ectthegreatest
odei
theleftsubtreetothecurre
t
odeifpLeftpLeftm_pRightpNodepNodem_pLeftpLeftCo
verttherightsubtreeifpNodem_pRightpRightCo
vertNodepNodem_pRighttrueCo
ecttheleast
odei
therightsubtreetothecurre
t
odeasRightwhetherpNodeistherightchildofitspare
telseretur
thegreatest
odei
thesubtreeOutputifasRightistrueretur
theleast
odei
thesubtree
fifpRightpNodem_pRightpRightpRightm_pLeftpNodeBSTreeNodepTemppNodeIfthecurre
t
odeistherightchildofitspare
tretur
theleast
odei
thetreewhoserootisthecurre
t
odeifasRightwhilepTempm_pLeftpTemppTempm_pLeftIfthecurre
t
odeistheleftchildofitspare
tretur
thegreatest
odei
thetreewhoserootisthecurre
t
odeelsewhilepTempm_pRightpTemppTempm_pRightretur
pTempCovertabi
arysearchtreei
toasorteddoubleli
kedlistI
puttheheadoftreeOutputtheheadofsorteddoubleli
kedlistBSTreeNodeCo
vertBSTreeNodepHeadOfTreeAswewa
ttoretur
theheadofthesorteddoubleli
kedlistwesettheseco
dparametertobetrueretur
Co
vertNodepHeadOfTreetrue
思路二对应的代码:
Covertasubbi
arysearchtreei
toasorteddoubleli
kedlistI
putpNodetheheadofthesubtree
f
pLastNodeI
Listthetailofthedoubleli
kedlist
voidCo
vertNodeBSTreeNodepNodeBSTreeNodepLastNodeI
ListifpNodeNULLretur
BSTreeNodepCurre
tpNodeCo
verttheleftsubtreeifpCurre
tm_pLeftNULLCo
vertNodepCurre
tm_pLeftpLastNodeI
ListPutthecurre
t
odei
tothedoubleli
kedlistpCurre
tm_pLeftpLastNodeI
ListifpLastNodeI
ListNULLpLastNodeI
Listm_pRightpCurre
tpLastNodeI
ListpCurre
tCo
verttherightsubtreeifpCurre
tm_pRightNULLCo
vertNodepCurre
tm_pRightpLastNodeI
ListCovertabi
arysearchtreei
toasorteddoubleli
kedlistI
putpHeadOfTreetheheadoftreeOutputtheheadofsorteddoubleli
kedlistBSTreeNodeCo
vert_Solutio
1BSTreeNodepHeadOfTreeBSTreeNodepLastNodeI
Listr