Last active
October 26, 2015 12:46
-
-
Save omeroot/47c2c8715bb12f540fbc to your computer and use it in GitHub Desktop.
binary tree visualization on ejs template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies" :{ | |
"express": "*", | |
"ejs" : "*", | |
"javascript-algorithms" : "*" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tırt