Constructing a binary search tree

As we know, a node can have two children and itself can represent a tree in a recursive manner. We will define our node class to be more functional and have all the required functionalities to find the maximum value, minimum value, predecessors, and successors. Later on, we will add the delete functionality as well for a node. Let's check the following code for a node class for a BST:

class Node {     public $data;     public $left;     public $right;     public function __construct(int $data = NULL) {        $this->data = $data;        $this->left = NULL;        $this->right = NULL;     }     public function min() {        $node = $this;        while($node->left) {          $node = $node->left;        }          return $node;     }     public function max() {          $node = $this;  while($node->right) ...

Get PHP 7 Data Structures and Algorithms now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.