链表
原地逆置
206. 反转链表 - 力扣(LeetCode)
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个 只用遍历一轮
class Solution {
public:ListNode* trainingPlan(ListNode* head, int cnt) {ListNode* f=head;//fastListNode* s=head;//slowint count=0;while(f!=NULL&&count<cnt){count++;f=f->next;}while(f!=NULL){f=f->next;s=s->next;}return s;}
};
静态链表
用数组描述的链表
跳表
跳跃表、跳跃列表,在有序链表的基础上增加了“跳跃”的功能,有序链表实现而二分查找。
1206. 设计跳表 - 力扣(LeetCode)
有点复杂 暂时不需要做