* @return {SplayTreeNode} Node having the maximum key value that * is less or equal to the specified key value.
(key)
| 156 | * is less or equal to the specified key value. |
| 157 | */ |
| 158 | findGreatestLessThan(key) { |
| 159 | if (this.isEmpty()) return null; |
| 160 | // Splay on the key to move the node with the given key or the last |
| 161 | // node on the search path to the top of the tree. |
| 162 | this.splay_(key); |
| 163 | // Now the result is either the root node or the greatest node in |
| 164 | // the left subtree. |
| 165 | if (this.root_.key <= key) { |
| 166 | return this.root_; |
| 167 | } else if (this.root_.left !== null) { |
| 168 | return this.findMax(this.root_.left); |
| 169 | } else { |
| 170 | return null; |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * @return {Array<*>} An array containing all the values of tree's nodes paired |
no test coverage detected