现在的位置: 首页 > 综合 > 正文

Ch4.5: find the (in-order tranversely) successor of a node in BST.

2014年07月07日 ⁄ 综合 ⁄ 共 378字 ⁄ 字号 评论关闭

There are 3 methods:

1. simply in order tranverse and get the ascending array, every next element is the successor of previous element.

2. It is Hawstein's method: There are 2 conditions: 

1st: have right child, go find the left least grand child.

2nd don't. go up to find the closest ancestor.

Here is whole code:

In order to verify, need to be careful, it is based on BST. So every simulation should have a BST structure. Random Tree will fail in this method.

抱歉!评论已关闭.