Populating Next Right Pointers in Each Node

void connect(TreeLinkNode *root) {

connect(root,NULL);

}

void connect(TreeLinkNode root, TreeLinkNode sub){

if(!root) return;

root->next=sub;

connect(root->left,root->right);

if(sub)

connect(root->right,sub->left);

else

connect(root->right,NULL);

}

};

Last updated

Was this helpful?