My simple non-iterative C++ code with O(1) memory
void connect(TreeLinkNode *root) {\n        if(!root)\n            return;\n        while(root -> left)\n        {\n            TreeLinkNode *p = root;\n       
    void connect(TreeLinkNode *root) {\n        if(!root)\n            return;\n        while(root -> left)\n        {\n            TreeLinkNode *p = root;\n            while(p)\n            {\n                p -> left -> next = p -> right;\n                if(p -> next)\n                    p -> right -> next = p -> next -> left;\n                p = p -> next;\n            }\n            root = root -> left;\n        }\n    }
[]