T
Thormod Johansen
Hi,
I have just read the article about iterators at
http://www.oreillynet.com/pub/a/network/2005/10/18/what-is-iterator-in-c-plus-plus.html?page=last
and I am wondering about what is ment by the sentence "list does not provide
random access iterators, though, not because it's impossible to implement,
but because it can't be implemented efficiently."
As I understand it, a vector is a single linked list and list is a double
linked list. Why is it harder to implement a efficient iterator in a double
linked than in a single linked list?
If I have the following requirements for a datastructure - be it vector or
list - which would you consider most efficient (fastest running time):
1 ) Be able to iterate through it looking for a specific value
2 ) Remove an element from the middle of the structure
3 ) Add an element in the front and in the back
I reckon that in the case of 2) a list would be fastest but how about the
two other cases?
Best regards.
I have just read the article about iterators at
http://www.oreillynet.com/pub/a/network/2005/10/18/what-is-iterator-in-c-plus-plus.html?page=last
and I am wondering about what is ment by the sentence "list does not provide
random access iterators, though, not because it's impossible to implement,
but because it can't be implemented efficiently."
As I understand it, a vector is a single linked list and list is a double
linked list. Why is it harder to implement a efficient iterator in a double
linked than in a single linked list?
If I have the following requirements for a datastructure - be it vector or
list - which would you consider most efficient (fastest running time):
1 ) Be able to iterate through it looking for a specific value
2 ) Remove an element from the middle of the structure
3 ) Add an element in the front and in the back
I reckon that in the case of 2) a list would be fastest but how about the
two other cases?
Best regards.