给定两个单链表,找出两个单链表的公共结点
LinkedList Search_Common_LNode(LinkedList& L1, LinkedList& L2)
{
LNode* p = L1->next;
LNode* q = L2->next;
LinkedList& common_L;
while(p) {
while(q) {
if(q->data == p->data) {
insert(common_L, q); //将公共结点插入到common_L链表中
q = L2->next; //重置q指针的位置
p = p->next; //p指针向后移动
} else {
q = q->next;
}
}
//重置q指针,q指针向后移动
p = p->next;
q = L2->next;
}
return common_L;
}
标签:结点,单链,LinkedList,找出,next,L2,common
From: https://www.cnblogs.com/xiaomitu/p/17445483.html