万隆的笔记 万隆的笔记
博文索引
笔试面试
  • 在线学站

    • 菜鸟教程 (opens new window)
    • 入门教程 (opens new window)
    • Coursera (opens new window)
  • 在线文档

    • w3school (opens new window)
    • Bootstrap (opens new window)
    • Vue (opens new window)
    • 阿里开发者藏经阁 (opens new window)
  • 在线工具

    • tool 工具集 (opens new window)
    • bejson 工具集 (opens new window)
    • 文档转换 (opens new window)
  • 更多在线资源
  • Changlog
  • Aboutme
GitHub (opens new window)
博文索引
笔试面试
  • 在线学站

    • 菜鸟教程 (opens new window)
    • 入门教程 (opens new window)
    • Coursera (opens new window)
  • 在线文档

    • w3school (opens new window)
    • Bootstrap (opens new window)
    • Vue (opens new window)
    • 阿里开发者藏经阁 (opens new window)
  • 在线工具

    • tool 工具集 (opens new window)
    • bejson 工具集 (opens new window)
    • 文档转换 (opens new window)
  • 更多在线资源
  • Changlog
  • Aboutme
GitHub (opens new window)
  • 数据结构与算法

    • 基础数据结构
    • 算法基本知识
    • 时间复杂度
    • 时间复杂度拓展
    • 排序算法
    • 二分法
    • 异或运算
    • 链表结构基础
      • 单链表
      • 双链表
    • 栈和队列
    • 递归
    • 哈希表和有序表
    • 其他
  • 设计模式

  • 编程方法论

  • 分布式设计与微服务理论

  • Leetcode

  • 程序员内功
  • 数据结构与算法
2022-02-13
目录

链表结构基础

# 链表结构基础

# 单链表

# 节点结构

常见单链表节点结构,也可实现成泛型。

public class Node {
  public int value;
  public Node next;

  public Node(int data) {
    value = data;
  }
}

# 反转单链表

public Node reverseLinkedList(Node head) {
  Node pre = null;
  Node next = null;
  while (head != null) {
    next = head.next;
    head.next = pre;
    pre = head;
    head = next;
  }
  return pre;
}

# 删除给定的值

public Node removeValue(Node head, int num) {
  while (head != null) {
    if (head.value != num) {
      break;
    }
    head = head.next;
  }
  Node pre = head;
  Node cur = head;
  while (cur != null) {
    if (cur.value == num) {
      pre.next = cur.next;
    } else {
      pre = cur;
    }
    cur = cur.next;
  }
  return head;
}

# 双链表

# 双链表节点结构

常见双链表节点结构,也可实现成泛型。

public class DoubleNode {
  public int value;
  public DoubleNode last;
  public DoubleNode next;

  public DoubleNode(int data) {
    value = data;
  }
}

# 反转双链表

public DoubleNode reverseDoubleList(DoubleNode head) {
  DoubleNode pre = null;
  DoubleNode next = null;
  while (head != null) {
    next = head.next;
    head.next = pre;
    head.last = next;
    pre = head;
    head = next;
  }
  return pre;
}

# 删除给定的值

public DoubleNode removeValue(DoubleNode head, int num) {
  while (head != null) {
    if (head.value != num) {
      break;
    }
    head = head.next;
  }
  DoubleNode pre = head;
  DoubleNode cur = head;
  while (cur != null) {
    if (cur.value == num) {
      pre.next = cur.next;
      cur.next.last = pre;
    } else {
      pre = cur;
    }
    cur = cur.next;
  }
  return head;
}
#数据结构与算法
上次更新: 5/21/2023, 11:34:33 PM
栈和队列

栈和队列→

最近更新
01
2025
01-15
02
Elasticsearch面试题
07-17
03
Elasticsearch进阶
07-16
更多文章>
Theme by Vdoing
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式