Code viewer for World: Binary tree (clone by Tom ...
// Cloned by Tom McAllister on 17 Oct 2020 from World "Binary tree" by "Coding Train" project 
// Please leave this clone trail here.
 
// const cw = 1500;
// const ch = 1200;
// const root_x = cw / 2;
// const root_y = ch / 20;
 //const ellipse_size = cw / 25;
const MAX = 3000;
const NONODES = MAX / 2;
const SHOWBUILD = true; // console log how we build the tree or not 


// Binary tree
var tree;


function setup() 
{
  $.getScript ( "/uploads/tom/node.js", function() {
    
    $.getScript ( "/uploads/tom/tree.js", function() {
        tree = new Tree();
        console.log ("=== build tree =================");
        for (var i = 0; i < NONODES; i++) 
        {
          var n = floor(random(0, MAX));
          tree.addValue(n);
        }
        tree.traverse();


        var x = floor(random(0, MAX));
        AB.msg( "This tree has " + NONODES + " nodes <br> console log shows how we search a sorted tree quickly <br> search tree for " + x + "<br>" );
        console.log ( "=== Search tree for " + x  + " ===================");
   
        var result = tree.search(x);
        if (result == null)   {
          AB.msg('Not found', 2);
        }
        else {
          AB.msg('Found', 2);
          console.log ("Well done. Press reload to search for another number in a new Tree!")
        }
    });

  });

}