C++ Iterative/Recursive
Recursive\n\nSimilar to a level-order traversal, even you are not allowed to use a queue, the next pointer provides you with a way to move to the next node in t
**Recursive**\n\nSimilar to a level-order traversal, even you are not allowed to use a `queue`, the `next` pointer provides you with a way to move to the next node in the same level.\n\n```cpp\nclass Solution {\npublic:\n    Node* connect(Node* root) {\n        Node *pre = root, *cur;\n        while (pre) {\n            cur = pre;\n            while (cur && cur -> left) { \n                cur -> left -> next = cur -> right;\n                if (cur -> next) {\n                    cur -> right -> next = cur -> next -> left;\n                }\n                cur = cur -> next;\n            }\n            pre = pre -> left;\n        }\n        return root;\n    }\n};\n```\n\n**Recursive**\n\nRecursively connect the left and right subtrees.\n\n```cpp\nclass Solution {\npublic:\n    Node* connect(Node* root) {\n        if (!root) {\n            return NULL;\n        }\n        if (root -> left) {\n            root -> left -> next = root -> right;\n            if (root -> next) {\n                root -> right -> next = root -> next -> left;\n            }\n            connect(root -> left);\n            connect(root -> right);\n        }\n        return root;\n    }\n};\n```
['Recursion', 'Binary Tree', 'Iterator', 'C++']