您的位置:首页 > 其它

有序单链表合并(递归法)

2015-07-31 21:51 253 查看
只是提供思路,缺少很多边界条件的检查

/* 递归法实现有序单链表的合并 */
LinkedList *MergeRecursive(LinkedList *head1, LinkedList *head2)
{
	if (head1 == NULL)
		return head2;
	if (head2 == NULL)
		return head1;
	LinkedList *head = NULL;
	if (head1->iValue < head2->iValue)
	{
		head = head1;
		head->next = MergeRecursive(head1->next, head2);
	}
	else
	{
		head = head2;
		head->next = MergeRecursive(head1, head2->next);
	}
	return head;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: