linked list

3 type of linked list
Three different kinds of linked lists exist:
  • Singly linked lists have a single pointer pointing to the next element in the list. The last pointer is empty or points to null, signaling the end of the list.
  • Doubly linked lists have two pointers, one pointing to the next element and one pointing to the previous element. The head node's previous pointer points to null and the tail node's next pointer points to null to signal the end of the list.
  • Circular linked lists usually represent buffers. They have no head or tail, and the primary issue is avoiding infinite traversals because of the cycle. These questions rarely come up in interview questions. Arrays are oftentimes a better substitute for a circular linked list, using the modulus operator to wrap around.

小技巧:
1. 固定head 指针
2. 每次加新节点的时候加在head


Comments

Popular posts from this blog

Unique Binary Search Trees

Longest prefix matching - trie