Code viewer for World: Binary tree (clone by Sagn...

// Cloned by Sagnik Chakraborty on 1 Oct 2022 from World "Binary tree" by "Coding Train" project 
// Please leave this clone trail here.
 

// Modified port of "01_binary_tree_viz" from AI course by Daniel Shiffman
// https://github.com/nature-of-code/NOC-S17-2-Intelligence-Learning/tree/master/week1-graphs

// Daniel Shiffman
// Nature of Code: Intelligence and Learning
// https://github.com/shiffman/NOC-S17-2-Intelligence-Learning


// canvas size 
const cw = 1500;
const ch = 900;
   
const root_x = cw / 2;
const root_y = ch / 10;
//const ellipse_size = cw / 25;


 
// range of numbers
const MAX = AB.randomIntAtoB(300,6000);

// how many nodes 
const NONODES = MAX / 2;

// console log how we build the tree or not 
const SHOWBUILD = true;


// Binary tree
var tree;

AB.msg("Building tree with "+NONODES+" nodes", 2);


function setup() 
{
 //createCanvas(cw,ch);


$.getScript ("/uploads/sagnikc3/node.js", function() {
   // console.log ("Got node");
    
$.getScript ( "/uploads/sagnikc3/tree.js", function() {
      //  console.log ("Got tree");
        
        
  // New tree
  tree = new Tree();
  
 
  console.log ("Build tree, number of nodes: "+NONODES);
  // Add random values
  for (var i = 0; i < NONODES; i++) 
  {
      var n = floor(random(0, MAX));
      // console.log ("adding node: " + n);
      tree.addValue(n);
  }

   AB.msg("<br> Tree built", 5);
  //background("lightgreen");

  // Traverse the tree
  tree.traverse();

  // Search the tree for random number 
  var x = floor(random(0, MAX));
  AB.msg( "<br> searching tree for " + x , 7);
  console.log ( "search tree for " + x );
   
  var result = tree.search(x);
  if (result == null)   AB.msg('<br> not found', 9);
  else                  AB.msg('<br> found', 9);
  
  
} );
} );

}