key = $key; $this->val = $val; if(!is_null($parent)) $this->parent = $parent; } /** * empty val */ public function doEmpty() { $this->val = null; } /** * JSON representation * * @return array|mixed */ public function jsonSerialize() { return [ 'key' => $this->getKey(), 'val' => $this->val, 'left' => $this->getLeft(), 'right' => $this->getRight(), ]; } /** * @param BSTNode|null $left * @return BSTNode */ public function setLeft(?BSTNode $left): BSTNode { $this->left = $left; return $this; } /** * @return BSTNode|null */ public function &getLeft(): ?BSTNode { return $this->left; } /** * @param BSTNode|null $right * @return BSTNode */ public function setRight(?BSTNode $right): BSTNode { $this->right = $right; return $this; } /** * @return BSTNode|null */ public function &getRight(): ?BSTNode { return $this->right; } /** * @param mixed|null $val * @return BSTNode */ public function setVal($val): BSTNode { $this->val = $val; return $this; } /** * @return mixed|null */ public function getVal() { return $this->val; } /** * @param null|string $key * @return BSTNode */ public function setKey(?string $key): BSTNode { $this->key = $key; return $this; } /** * @return null|string */ public function getKey(): ?string { return $this->key; } /** * @param BSTNode|null $parent * @return BSTNode */ public function setParent(?BSTNode $parent): BSTNode { $this->parent = $parent; return $this; } /** * @return BSTNode|null */ public function &getParent(): ?BSTNode { return $this->parent; } }