前言
Linus Benedict Torvalds : RTFSC – Read The Funning Source Code
概述
LinkedList is an implementation of List, backed by a doubly-linked list. All optional operations including adding, removing, and replacing elements are supported. All elements are permitted, including null. This class is primarily useful if you need queue-like behavior. It may also be useful as a list if you expect your lists to contain zero or one element, but still require the ability to scale to slightly larger numbers of elements.
LinkedList的数据结构是双向列表,列表中的每个节点都包含了对前一个和后一个元素的引用。
使用
|
|
初始化
|
|
添加元素
|
|
删除元素
|
|
查找元素
|
|
特性
优点
- 对于增加、删除、移动效率都非常高。因为改动只需要针对链表的前后节点。
- 因为是链表,对于内存来说是不连续的,空间利用率较高。
缺点
- 因为是链表结构,在查询上只能从头往后查找,对于效率来说十分低下。
- 因为是链表,对于内存来说是不连续的,在优化内存分配上不太友好。