Next in BST X59546


Statement
 

pdf   zip   main.cc

html

A Binary Search Tree is a structure in the form of a binary tree, satisfying that for every node, the values of all the nodes in its left subtree are smaller than its value, and the values of all the nodes in its right subtree are greater (we are assuming the tree has no repeated nodes).

Consider the following implementation of a node of a BST:

struct bst_node { int m_value; bst_node* m_parent = nullptr; bst_node* m_left = nullptr; bst_node* m_right = nullptr; };

Implement the function

bst_node* next(bst_node* node);

that returns the node with the smallest value that is greater than the value of the current node, or nullptr if the current node has the greatest value.

Observation You only need to submit the required classes; your main program will be ignored. Strictly obey the type definitions of the statement.

Information
Author
Language
English
Official solutions
C++
User solutions
C++