// Cloned by Dheeraj Putta on 25 Oct 2020 from World "Binary tree (clone by Fergus)" by Fergus
// Please leave this clone trail here.
// Cloned by Fergus on 22 Oct 2020 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 = 900;
const ch = 900;
const root_x = cw / 2;
const root_y = ch / 10;
const ellipse_size = cw / 25;
// range of numbers
const MAX = 600;
const MIN = 100;
// how many nodes
const NONODES = 1000;
//MAX / 2;
// console log how we build the tree or not
const SHOWBUILD = true;
// Binary tree
var tree;
function setup()
{
//createCanvas(cw,ch); //Draws the tree.
$.getScript ( "/uploads/fergus24/node.js", function() {
// console.log ("Got node");
$.getScript ( "/uploads/fergus24/tree.js", function() {
// console.log ("Got tree");
// New tree
tree = new Tree();
console.log ("=== build tree =================");
// Add random values
for (var i = 0; i < NONODES; i++)
{
var n = floor(random(MIN, MAX));
// console.log ("adding node: " + n);
tree.addValue(n);
}
//background("lightgreen");
// Traverse the tree
tree.traverse();
AB.msg('# of nodes = ' + NONODES + "<br>",1);
AB.msg('Min number = ' + MIN + "<br>",2);
AB.msg('Max number = ' + MAX + "<br>",3);
// Search the tree for random number
var x = floor(random(MIN, MAX));
AB.msg( "console log shows how we search a sorted tree quickly <br> search tree for " + x + "<br>",4 );
console.log ( "=== search tree for " + x + " ===================",4);
var result = tree.search(x);
if (result == null) AB.msg('not found'+ "<br>", 6);
else AB.msg('found'+ "<br>", 6);
} );
} );
}