Using the right pointer of the node, the leaf node of a binary tree inherits a singly linked list from left to right.
void link(BTNode* p,BTNode* head,BETNode* tail)
{
if(p)
{
if(!p->left&&!p->right)
{
if(head==NULL)
{
head=p;
tail=p;
}
else
{
tail->next=p;
tail=p;
}
}
link(p->left,head,tail);
link(p->right,head,tail);
}
}