My recursive solution
void connect(TreeLinkNode *root) {\n        if( root == NULL || root->left == NULL && root->right == NULL )        //{} \\ {0}\n        {\n           return;\n 
    void connect(TreeLinkNode *root) {\n        if( root == NULL || root->left == NULL && root->right == NULL )        //{} \\ {0}\n        {\n           return;\n        }\n        \n        TreeLinkNode *p, *q;\n        p = root->left;\n        q = root->right;\n        p->next = q;\n        while( p->right != NULL )\n        {\n            p = p->right;\n            q = q->left;\n            p->next = q;\n        }\n        \n        connect( root->left );\n        connect( root->right );\n    }
[]