将二叉树的叶子节点串成链表

利用节点的右指针将一颗二叉树的叶子节点从左往右传承一个单链表。

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);
	}
} 

猜你喜欢

转载自blog.csdn.net/Cxf2018/article/details/105553202