链表
之前看过了动态数组,栈和队列,虽然我们把第一个叫做动态数组,但是,他们的底层实质上还是静态数组。靠
resize来实现动态数组。而链表是真正的数据结构
- 链表需要一个节点。
- 数据存储在链表中
相当于是一串火车,将数据放在车厢中,两个车厢之间还需要一个个节点来相互串联。
优点:实现了真正的动态。
缺点:无法进行随机访问
public class LinkedList<E> {
private class Node {
public E e;
public Node next;
public Node(E e) {
this(e, null);
}
public Node(E e, Node next) {
this.e = e;
this.next = next;
}
public Node() {
this(null, null);
}