Subscribed unsubscribe Subscribe Subscribe

Takefumi Yamamura's blog

This blog is for my memorandum.

Takefumi Yamamura's b!og

This blog is for my memorandum

Successor

prblme

Write an algorithm to find the “next” node(i.e., in-order successor) of a given node in a binary search tree. (You may assume that each node has a link to its parent or you can get the root node)

how to solve

“Next” node means that the most nearest parent node which is right side of a given node. So we should find it.

code 1

When I can get the root node

code 2

When I get the parent node of each node

Remove all ads