You're both wrong. They just made a decision; they wanted iterators to be faster on average. Nothing about an iterator for a singly linked list suggests that an implementation of 'erase' or 'insert' can't be O(1).If you have an iterator pointing to the last element then you could not delete the item it points to AND correctly update the ltail pointer in anything less than O(n) time. That's on top of the fact that iterating through the list is also O(n). Therefore if you were to iterate over the list backwards, deleting as you go, it would be O(n*n).
I'm pretty sure this would be the main reason why there is no tail pointer.
Example: I think DinkumWare provides the 'slist' class as an extension to the STL where 'insert' and 'erase' are constant.
Soma



LinkBack URL
About LinkBacks




CornedBee