Can'T Solve this problem

Hi there
The doubt i am asking for is for this question ->https://algorithms.tutorialhorizon.com/in-a-binary-tree-create-linked-lists-of-all-the-nodes-at-each-depth/

I am not able to do this after trying more than one hour
this is my function
vector<Btnode> LinkedListHead(Btnode root)
{
queue<Btnode> q;
forward_list l;
Btnode * head=NULL;
Btnode
tail=NULL;
q.push(root);
q.push(NULL);
vector<Btnode*> v;
while(!q.empty())
{
Btnode * cur=q.front();
q.pop();
if(cur!=NULL)
{
if(head==NULL)
{
l.push(cur);
}
if(root->left!=NULL)
{
q.push(root->left);
}
if(root->right!=NULL)
{
q.push(root->right);
}
}
else{
l.push(NULL);
q.pop();
v.push_back(head);
if(!q.empty())
{
q.push(NULL);
}
}
}
return v;
}

PLease provide the solution code with explanation in comments
THanks:)

Hi @Coderdeep
refer this --> https://www.geeksforgeeks.org/connect-nodes-at-same-level/

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.