LinkedLists Flashcards
Inserting a Node in the middle
(1) Initiaize new node (2) point newNode.next to desiredPrev.next (3) point desiredPrev.next to newNode ; O(1)
Inserting a Node at the head
(1) Initiaize new node (2) point newNode.next to head (3) point head to newNode ; O(1)
Inserting a Node at the tail
(1) Initialize new node (2) point tail.next to newNode or find first Node with .next == null [last node] (3) point taill to new Node ; O(1) or O(n) if have to search for tail
Deleting a Node in the middle
(1) find prev of deleteNode (2) point prev.next to deleteNode ; O (N) to search for prev
Deleting a Node at the head
(1) point head to head.next ; O(1)
Deleting a Node at the tail
(1) find prev of tailNode (2) point prev.next to null ; O(N) for search for prev