EXERCISE · AlgoCasts

Binary search tree

1) Implement the Node class to create a binary search tree. The constructor should initialize values 'data', 'left', and 'right'.

4 testsAlgoCastsGPL-3.0exercise 24 of 26

Directions

Directions

1) Implement the Node class to create a binary search tree. The constructor should initialize values 'data', 'left', and 'right'. 2) Implement the 'insert' method for the Node class. Insert should accept an argument 'data', then create an insert a new node at the appropriate location in the tree. 3) Implement the 'contains' method for the Node class. Contains should accept a 'data' argument and return the Node in the tree with the same value.

Try it first#

Copy the stub, make the 4 tests pass on your machine, then open the solution. The reveal is remembered per page in this browser.

JSexercises/bst/index.js
class Node {} module.exports = Node;

See also