Creating a BinaryTree using Javascript

Web DevelopmentFront End TechnologyJavascript

Let us understand how we're going to create and represent a binary search tree in Javascript. We'll first need to create the class BinarySearchTree and define a property Node on it. 


class BinarySearchTree {
   constructor() {
      // Initialize a root element to null.
      this.root = null;

BinarySearchTree.prototype.Node = class {
   constructor(data, left = null, right = null) { = data;
      this.left = left;
      this.right = right;

We've simply created a class representation of our BST class. We'll fill this class in as we proceed to learn functions that we'll add to this structure.

Published on 28-Jun-2018 11:14:34