> For the complete documentation index, see [llms.txt](https://yangsx95.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yangsx95.gitbook.io/notes/programming-language/java/ji-he/list/linkedlist.md).

# LinkedList

Linked代表链，他的底层实现就是**双向链表**，而不是数组。他既实现了Dueue、又实现了List。其中Deque继承自Queue，是一种**双端队列**的操作抽象。

![image-20220303171039006](https://2351062869-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7b2CdwBN9liniVJpfEAc%2Fuploads%2Fgit-blob-09a1955fdb3c499ac8bd61b32ca075a616f76b95%2Fimage-20220303171039006.png?alt=media)

1. `LinkedList`的内部是一个双向链表，链表的每个节点由`Node`类定义，他拥有两个指针：
2. 双向链表一般会记录头节点和尾节点，以及整个链表的长度：
3. `add`方法将会在链表的结尾链接一个新的元素，他会先将元素封装为Node并将`last`、`size`更新。
4. `get`方法根据索引获取元素，将会使用循环的方式一个个寻找元素，**当要获取的索引在链表的前半段，则从前往后找，如果在链表的后半段，则从后往前找**：
