binary-tree-neighbors
Label nodes of a binary tree with nearest right-hand neighbor
Given a structure like the following:
O
/ \
O O
/ / \
O O O
/ / \
O O O
/ \
O O
The program will label the tree with the nearest right-hand neighbor as follows:
O-->null
/ \
O-->O-->null
/ / \
O-->O-->O-->null
/ / \
O------>O-->O-->null
/ \
O-->O-->null
Installation
npm install binary-tree-neighbors --save
Usage
Example
0
/
0
/
0
Code
var traverse = ; var root = neighbor: null children: children: null null null console; console; ; console; console;
Output
Before
{
"children": [
{
"children": [
null,
null
]
},
null
],
"neighbor": null
}
After
{
"children": [
{
"children": [
null,
null
],
"neighbor": null
},
null
],
"neighbor": null
}
License
Copyright (c) 2015 Claudio Procida