数组 & 链表

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.
}
posted @ 2019-12-23 13:44  辛湛  阅读(94)  评论(0)    收藏  举报