Skip to content

Instantly share code, notes, and snippets.

@omeroot
Last active October 26, 2015 12:46
Show Gist options
  • Save omeroot/47c2c8715bb12f540fbc to your computer and use it in GitHub Desktop.
Save omeroot/47c2c8715bb12f540fbc to your computer and use it in GitHub Desktop.
binary tree visualization on ejs template
<html>
<head></head>
<body>
<% var queue = [],l=null,r=null; %>
<% queue.push(btree) %>
<% while(queue.length > 0){ %>
<% var s = queue.shift() %>
<% if(s.left !== null){queue.push(s.left);l = s.left} if(s.right !== null){queue.push(s.right);r = s.right} %>
<% if(l !== null){ %>
<ul><%= s.data.id %>
<ul> <%= l.data.id %> </ul>
<% l = null %>
<% }else{%>
<ul> <%= s.data.id%>
<% } %>
<% if(r !== null){ %>
<ul> <%= r.data.id %> </ul>
</ul>
<% r = null %>
<% }else{%>
</ul>
<% } %>
<% } %>
</body>
</html>
{
"dependencies" :{
"express": "*",
"ejs" : "*",
"javascript-algorithms" : "*"
}
}
var express = require('express');
var algojs = require('javascript-algorithms');
var btree = new algojs.BinarySearchTree();
btree.insert({name: "omer", surname : "demircan", id:7},function(a, b){
return a.id > b.id;
});
btree.insert({name: "eray", surname : "arslan", id:6},function(a, b){
return a.id > b.id;
});
btree.insert({name: "pamir", surname : "cevik", id:5},function(a, b){
return a.id > b.id;
});
btree.insert({name: "eyup", surname : "basturk", id:3},function(a, b){
return a.id > b.id;
});
btree.insert({name: "node", surname : "js", id:9},function(a, b){
return a.id > b.id;
});
btree.insert({name: "markakod", surname : "family", id:10},function(a, b){
return a.id > b.id;
});
var app = express();
app.set("view engine","ejs");
app.set("views",__dirname);
app.get('/',function(req, res){
res.render('index',{btree : btree.root});
});
app.listen(1337,function(){
console.log('listening 1337 port');
});
@omeroot
Copy link
Author

omeroot commented Oct 26, 2015

tırt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment