sir I do not understand why you check
if(!q.empty( ))
q.push(nullptr);
because earlier you just popped it out why do you again pushed it?
Binary tree level order traversal 2
Hey @mzk1994
We are pushing NULL pointer to differentate between every level
like we start with Queue == rootnode NULL
Then we pop rootnode and
THEN we push rootnode->L & rootnode->R
Queue == NULL rootnode->L rootnode->R
then we see NULL we pop it and push another NULL so
Queue == rootnode->L rootnode->R NULL
see null will keep different levels seperate
Now check if (!q.empty()) because say once all the nodes are processed then Queue will remain with single NULL and we pop it and if we push NULL again then it will be stuck in infinite loop