Java???????????????LinkedList
???????????? ???????[ 2016/6/2 11:00:40 ] ??????????? ???????????
???????????
????LinkedList???????List????Deque????????????????????????????????????????????У?Queue????????????????????Stack??????????????LinkedList?????????????????????????????????????????LinkedList????????????Java???????????????????Stack????????????Java???????????????Queue????????????????????????????У????????ArrayDeque?????????LinkedList???????????????????????????????
????LinkedList??????????????????????????????????????????????????????????????????List????????????????Queue??Stack???Deque???????????????????????????????????????Node?????LinkedList???first??last???÷????????????????????????????????????ν????????????????????first??last?????null??
//Node?????
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;
}
}
????LinkedList????????????????и??±?????????????????????????λ????β?????????????????????Ч??LinkedList???????????synchronized?????????????????????????????????Collections.synchronizedList()??????????а????
????????????
????add()
????add()???????????汾???????add(E e)???÷?????LinkedList???β?????????????last????????β?????β?????????????????????????????????????ü???????????add(int index?? E element)???÷???????????±????????????????????????????????λ???????????????????????????
???????????????????add(E e)????????????
//add(E e)
public boolean add(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++;
return true;
}
????add(int index?? E element)?????????????????????????1.?????index?????????λ???2.???????????????????
//add(int index?? E element)
public void add(int index?? E element) {
checkPositionIndex(index);//index >= 0 && index <= size;
if (index == size)//????λ?????β???????б????????
add(element);
else{
Node<E> succ = node(index);//1.?????index?????????λ??
//2.???????????????????
final Node<E> pred = succ.prev;
final Node<E> newNode = new Node<>(pred?? e?? succ);
succ.prev = newNode;
if (pred == null)//????λ???0
first = newNode;
else
pred.next = newNode;
size++;
}
}
????????????е?node(int index)?????????СС??trick???????????????????????????????????β?????????峯??????????????????index < (size >> 1)???????index??????????????
????remove()
????remove()????????????汾?????????????????????????????remove(Object o)????????????????±??????remove(int index)??
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11