2 ms·
That example involves inserting (and deleting) elements at a specific index, which means you would have to traverse (on average) half of the linked-list each ti
by gizmo686 13y ago
That example involves inserting (and deleting) elements at a specific index, which means you would have to traverse (on average) half of the linked-list each time.
Generally, when I work with linked-lists (excluding functional programming) I only delete elements after I already have a pointer to them for something else. Similarly, I generally do not care about the order of elements, so I can either insert a new element at whatever index my cursor happens to be at, or append them to the end.
- chmike 13y agoThese are specific use case. Indeed in some cases lists are more efficient than arrays. The advice to use arrays instead of linked list is a rule thumb. Not all programmers are still sucking their thumb. ;)