3 ms·
> but that inserts in the middle necessitate looping through the linked list until you get to the correct index, which is a O(n) operation. Not if you save the
by dragontamer 6y ago
> but that inserts in the middle necessitate looping through the linked list until you get to the correct index, which is a O(n) operation.
Not if you save the node you are working on. Inserting (when you have a node) is simply:
NewNode = malloc(...) or new or something.
NewNode.next = node.next
node.next = NewNode
- penetraitor69 6y agoOh, gotcha; I just meant in the general case.