Part 13 of 15 in Binary Search Trees  

Inorder successor of Binary Search Tree by phantom11

Problem statement

Write a function to find the inorder successor of a node in a binary search tree. A binary search tree is a binary tree in which value of all the nodes left of a node are lesser than it and value of all the nodes right of node are greater than it. You may assume that there are no duplicate values in the tree. Inorder successor of a node is the node you would visit after a given node when traversing the tree in inorder traversal.


You need to write a function named "Node* GetSuccessor(Node* root, int data)" that will take root of a binary search tree and the data of the node whose inorder successor we need to find as arguments.


Your function must return pointer to node which is the inorder successor of the given data. If such a node does not exists or the data given is not found in the tree, simply return a NULL.

To try out your code

Sign in

Sign up