Happy Coding

This blog is for my memorandum about programming and English.

Happy Coding

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

code 3

More easy way

gist.github.com