数组 & 链表
Array
Advantage: very fast access of each item.O(1)
Disadvantage:
1. slide a lot of items over one place to make room. O(n)
2. Fixed length, have to allocate a whole new array and move all the ints from the old array to the new one. O(n)
Linked List
Each node has:
- an item
- a reference to next node in list
public class ListNode {
public int item; // ListNode is a recursive type
public ListNode next; // Here we’re using ListNode before we’ve finished declaring it.
}

浙公网安备 33010602011771号