|
First-level containers include "sequential containers" and "associative containers", and container adapters do not belong to one-tier containers Iterators are used to access and control elements in a first-level container Why is the container adapter not supported? Because the container adapter relies on a specific container implementation. |
|
Forward iterators can also support forward + + and back + + |
|
Lis supports bidirectional iterators, however queue is a container adapter and does not support iterators |
|
The input iterator is used to read the data, and the output iterator is used to write the data, so the output iterator is used for the left value |
|
Stack is a container adapter and cannot use iterators |
|
After the set is saved, it is sorted by the rule (default from small to sort) |
|
int Main () { list<int> IList; List<int>::iterator it1 = ilist.begin (); List<int>::iterator it2 = ilist.end (); if (It1 > it2) { "it1 > It2" << Endl; } return 0 ;} In the following specific analysis. |
1, It1,it2 can not compare size, because It1,it2 is a list of iterators, is a bidirectional iterator
2, IT3,IT4 can compare size, because IT3,IT4 is a vector iterator, support random iterators
First of all, why Vector,deque support random iterators, list does not support random iterators?
Vector,deque is a linear structure that can be accessed randomly
List is a linked list is structured and cannot be accessed randomly
Bidirectional iterators cannot compare sizes, random iterators can compare sizes
A bidirectional iterator cannot compare size because the address of an element on a linked list is not contiguous and the size of the comparison is meaningless
A random iterator can compare size, because it refers to the address of an element in a contiguous space that is contiguous, and the size of the comparison is meaningful
Try to use
for (Itr3=li3.begin (); ITR3! = Li3.end (); itr3++)
Instead of
for (Itr3=li3.begin (); Itr3 < Li3.end (); itr3++)
Because the former is common to various iterators, the latter is only common to random iterators , and once you consider moving forward from backward, you need to change "<" to ">", for example
for (Itr3=li3.rbegin (); ITR3 > Li3.rend (); itr3--)
Iterator Discussions for container classes