Java recursive and iterative solutions.
    \n    // dfs iteratively \n    public void connect1(TreeLinkNode root) {\n        Stack<TreeLinkNode> stack = new Stack<>();\n        stack.push(root);\n   
        \n    // dfs iteratively \n    public void connect1(TreeLinkNode root) {\n        Stack<TreeLinkNode> stack = new Stack<>();\n        stack.push(root);\n        while (!stack.isEmpty()) {\n            TreeLinkNode n = stack.pop();\n            if (n != null) {\n                if (n.right != null) {\n                    n.left.next = n.right;\n                    if (n.next != null) {\n                        n.right.next = n.next.left;\n                    }\n                }\n                stack.push(n.right);\n                stack.push(n.left);\n            }\n        }\n    }\n    \n    // bfs iteratively\n    public void connect2(TreeLinkNode root) {\n        Queue<TreeLinkNode> queue = new LinkedList<>();\n        queue.add(root);\n        while(!queue.isEmpty()) {\n            TreeLinkNode n = queue.poll();\n            if (n != null) {\n                if (n.right != null) {\n                    n.left.next = n.right;\n                    if (n.next != null) {\n                        n.right.next = n.next.left;\n                    }\n                }\n                queue.add(n.left);\n                queue.add(n.right);\n            }\n        }\n    }\n    \n    // dfs recursively\n    public void connect(TreeLinkNode root) {\n        if (root != null) {\n            if (root.right != null) {\n                root.left.next = root.right;\n                if (root.next != null) {\n                    root.right.next = root.next.left;\n                } \n            }\n            connect(root.left);\n            connect(root.right);\n        }\n    }
['Depth-First Search', 'Breadth-First Search', 'Recursion', 'Iterator', 'Java']