二叉树转换链表
treeRoot =
new BioTree(1,new BioTree(2,new BioTree(3),new BioTree(4)
),new BioTree(5,new BioTree(6)
)
);
function recur(node,handler) {
if (node.left) {
recur(node.left,handler);
}
handler(node);
if (node.right) {
recur(node.right,handler);
}
}
let head = null;
let pre = null;
recur(treeRoot,v => {
if (pre === null) {
pre = v;
head = v;
} else {
pre.right = v;
pre = pre.right;
}
});
console.log('=================');
let cur = head
while(cur) {
console.log(cur.data);
cur = cur.right;
}