dev-resources.site
for different kinds of informations.
Print left view of binary tree
Published at
5/24/2022
Categories
javascript
programming
algorithms
Author
Bvnkumar
class Node{
constructor(data,left,right){
this.data=data;
this.left=left;
this.right=right;
}
}
const tree=new Node(10);
tree.left=new Node(1)
tree.right=new Node(3)
tree.left.left=new Node(4)
tree.left.right=new Node(5)
tree.right.right=new Node(6)
tree.right.left=new Node(2);
tree.right.right.left=new Node(7)
tree.left.right.left=new Node(8)
tree.left.right.right=new Node(9)
tree.left.right.left.left=new Node(10);
let max_level=0;
function leftsideView(node,level){
if(node==null){
return null;
}
if(max_level<level){
console.log(node.data)
max_level=level;
}
leftsideView(node.left,level+1);
leftsideView(node.right,level+1);
}
leftsideView(tree,1)
Articles
12 articles in total
LRU (Least Recently Used) Cache Data Structure
read article
Observer Design Pattern using Javascript
read article
Javascript Factory Design Pattern
read article
Longest string without repeating characters in javaascript
read article
Print left view of binary tree
currently reading
Binary search algorithm implementation in JavaScript
read article
Javascript Binary heap data structure
read article
Javascript Linked List data structure
read article
Javascript Binary Tree data structure
read article
Javascript Queue data structure
read article
Javascript Set data structure
read article
Javascript Stack Data Structure.
read article
Featured ones: