0
点赞
收藏
分享

微信扫一扫

LinkedList源码解析

seuleyang 2022-03-26 阅读 51
ideajava

LinkedList总结

  • 双向链表结构,查询慢,增删快
  • 线程不安全

LinkedList分点详解

LinkedList继承实现情况

在这里插入图片描述

LinkedList数据结构

  1. 链表节点类型为内部类
private static class Node<E> {
        E item;
        Node<E> next;
        Node<E> prev;

        Node(Node<E> prev, E element, Node<E> next) {
            this.item = element;
            this.next = next;
            this.prev = prev;
        }
    }
  1. 默认新增数据就是直接在链表终端添加元素
//1.添加元素
public boolean add(E e) {
        linkLast(e);
        return true;
    }

//2.在链表末尾添加元素
void linkLast(E e) {
		//链表末节点
        final Node<E> l = last;
        //新节点
        final Node<E> newNode = new Node<>(l, e, null);
        //链表末位节点更新
        last = newNode;
        if (l == null)
            first = newNode;
        else
            l.next = newNode;
        size++;
        modCount++;
    }
举报

相关推荐

0 条评论