One base case problem

when i am writing root==NULL after k==1 the last level is not printing why?

please share your code.
thanks

void Kthlevel(Treenode*root,int level)
{
if(level==1)
{
cout<data<<" ";
return;
if(root==NULL)
return;
}
for last level this is not printing

the data variable you are referring in your code, it should be root->data. right?
and if you check root==NULL later, root->data will result in run time error. since you can’t access data of NULL valued pointer.

thanks

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.