Java 資料結構總結 (未完成)

Borris發表於2019-10-31

Stack

Queue

Linked List

Linear data structure. The Linked List is a list consists of nodes and where each node contains a reference, or address indicates its next node in the list.

  • Array vs Linked List
    • array must has a size when initialzie, while linked list keeps increasing size when adding nodes into the list; Linked list is space saving / dynamic size.
    • get an element from the array costs constant time, while it takes O(n) in a linked list;
    • insertion or deletion cost O(n) in array, while only constant time in linked list.

      Singly Linked List

  • Head only contains address of first node in a linked list. It gives easy access to the node and simplify lots of linked list operations. (sentinel node)
  • The address filed for last node in the linked list is null.
  • No access to previous nodes.

相關文章