5 min easy to understand straight forward


#1

void Solution::connect(TreeLinkNode* A) {

queue<TreeLinkNode *> q;
if(A==NULL)
    return ;
q.push(A);
q.push(NULL);
while(!q.empty() && q.front()!=NULL)
{
    while(q.front()!=NULL)
    {
        TreeLinkNode *front=q.front();
        q.pop();
        front->next=q.front();
        
        if(front->left) q.push(front->left);
        if(front->right) q.push(front->right);
    }
    q.pop();
    q.push(NULL);
}
return ;

}