nowcode
給定乙個二叉樹和其中的乙個結點,請找出中序遍歷順序的下乙個結點並且返回。注意,樹中的結點不僅包含左右子結點,同時包含指向父結點的指標。
public
class
treelinknode
}
/*
public class treelinknode }*/
public
class
solution
else
}return null;
}}
static arraylist
a=new
arraylist
<
>()
;public
static
void
inorder
(treelinknode proot)
}public treelinknode getnext
(treelinknode pnode)
inorder
(pnode)
;for
( i=
0;isize()
;i++)}
return null;
}
劍指offer 8 二叉樹的下乙個結點
include include includetypedef int datatype typedef struct bstreenode bstreenode bstreenode createnode int data 首先利用棧實現二叉樹的非遞迴中序遍歷,從根結點開始,當根結點不為空或者棧不為...
劍指Offer 8 二叉樹的下乙個節點
給定一棵二叉樹和其中的乙個結點,如何找出中序遍歷順序的下乙個結點?樹中的結點除了有兩個分別指向左右子結點的指標以外,還有乙個指向父結點的指標。主要分為兩種情況 如果乙個節點的右子樹不為空,那麼在中序遍歷的下乙個節點就是其 右子樹的最左節點 如果乙個節點的右子樹為空,那麼在中序遍歷的下乙個節點就是其 ...
劍指offer 8 二叉樹的下乙個節點
給定乙個二叉樹和其中乙個節點,找出該節點在中序遍歷序列中的下乙個節點。注意 樹中的節點除了有兩個分別指向左右子節點的指標,還有乙個指向父節點的指標。如果給定的節點是中序遍歷序列的最後乙個,則返回空節點。二叉樹一定不為空,且給定的節點一定不是空節點。分情況討論即可,如下圖所示 如果當前節點有右孩子,則...