算法竞赛备赛——【数据结构】链表

链表

原地逆置

206. 反转链表 - 力扣(LeetCode)

C++ 复制代码
class Solution {
public:
    ListNode* reverseList(ListNode* head) {//链表无头节点 原地逆置 
        ListNode* pre=head;
        ListNode* cur=NULL;
        ListNode* t=NULL;//t=head->next 若head指向空链表会报错 非法访问其他空间
        while(pre!=NULL){
            t=pre->next;
            pre->next=cur;
            cur=pre;
            pre=t;
        }
        head=cur;
        return head;
    }
};

快慢指针

LCR 140. 训练计划 II - 力扣(LeetCode)

让两个指针相差k个 只用遍历一轮

C++ 复制代码
class Solution {
public:
    ListNode* trainingPlan(ListNode* head, int cnt) {
        ListNode* f=head;//fast
        ListNode* s=head;//slow
        int count=0;
        while(f!=NULL&&count<cnt){
            count++;
            f=f->next;
        }
        while(f!=NULL){
            f=f->next;
            s=s->next;
        }
        return s;
    }
};

静态链表

用数组描述的链表

跳表

跳跃表、跳跃列表,在有序链表的基础上增加了"跳跃"的功能,有序链表实现而二分查找。

1206. 设计跳表 - 力扣(LeetCode)

有点复杂 暂时不需要做

相关推荐
静听山水2 分钟前
Redis核心数据结构-ZSet
数据结构·redis
D_evil__4 分钟前
【Effective Modern C++】第五章 右值引用、移动语义和完美转发:24. 区分万能引用和右值引用
c++
铉铉这波能秀13 分钟前
LeetCode Hot100数据结构背景知识之字典(Dictionary)Python2026新版
数据结构·python·算法·leetcode·字典·dictionary
蜡笔小马22 分钟前
10.Boost.Geometry R-tree 空间索引详解
开发语言·c++·算法·r-tree
唐梓航-求职中31 分钟前
编程-技术-算法-leetcode-288. 单词的唯一缩写
算法·leetcode·c#
仟濹32 分钟前
【算法打卡day3 | 2026-02-08 周日 | 算法: BFS】3_卡码网99_计数孤岛_BFS | 4_卡码网100_最大岛屿的面积DFS
算法·深度优先·宽度优先
Ll130452529836 分钟前
Leetcode二叉树part4
算法·leetcode·职场和发展
林开落L36 分钟前
从零开始学习Protobuf(C++实战版)
开发语言·c++·学习·protobuffer·结构化数据序列化机制
林开落L39 分钟前
从入门到了解:Protobuf、JSON、XML 核心解析(C++ 示例)
xml·c++·json·protobuffer·结构化数据序列化机制
Queenie_Charlie43 分钟前
stars(树状数组)
数据结构·c++·树状数组