💡JavaScript BFS & DFS Solution
The Idea - BFS\n1. BFS using queue\n2. as we are shifing node, connect it to the next in queue\njavascript\nvar connectBFS = function(root) {\n    if (root == n
#### The Idea - BFS\n1. BFS using queue\n2. as we are shifing node, connect it to the next in queue\n``` javascript\nvar connectBFS = function(root) {\n    if (root == null) return root;\n    let queue = [root];\n    while(queue.length!=0) {\n        let next = [];\n        while(queue.length!=0) {\n            let node = queue.shift();\n            node.next = queue[0]||null;\n            if (node.left!=null) {\n                next.push(node.left);\n                next.push(node.right);\n            }\n        }\n        queue = next;\n    }\n    return root;\n};\n```\n#### The Idea - DFS\n1. pre order scan \n2. set child nodes arrangement before resursion\n``` javascript\nvar connect = function(root) {\n    if (root == null || root.left == null) return root;\n    root.left.next = root.right;\n    root.right.next = root.next ? root.next.left:null;\n    connect(root.left);\n    connect(root.right);\n    return root;\n}\n```
['JavaScript']