相交链表(Intersection of Two Linked Lists): 给定两个单链表,判断它们是否相交,并返回相交的起始节点。假设链表中无环。

C++程序实现链表相交节点查找

#include<iostream>
#include<stack>
#include<vector>
#include<string>
#include<algorithm>
#include<unordered_map>
#include<climits>
#include<queue>
#include<unordered_set>
#include<cctype>
#include<sstream>
using namespace std;
#define maxsize 100

typedef struct L {
    int data;
    L* next;
}*l;

l xx(l a, l b) {
    int ln1 = 0;
    int ln2 = 0;
    l q1 = a;
    l q2 = b;

    // 计算两个链表的长度
    while (q1) {
        ln1++;
        q1 = q1->next;
    }
    while (q2) {
        ln2++;
        q2 = q2->next;
    }

    // 重新初始化指针位置
  &

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值