The list iterator function

function function
begin() Returns a bidirectional iterator to the first element in the container (forward iterator)
end() Returns a bidirectional iterator that refers to the position following the position of the last element in the container. (forward iterator)
rbegin() Returns a reverse bidirectional iterator to the last element
rend() Returns a reverse bidirectional iterator to the position before the position of the first element
cbegin() The forward iterator has the same function as begin(), except that it adds a const attribute that cannot be used to modify elements
cend() The forward iterator has the same function as end(), except that it adds a const attribute that cannot be used to modify elements
crbegin() The reverse iterator has the same function as rbegin(), except that it adds a const attribute that cannot be used to modify elements
crend() The reverse iterator has the same function as rend(), except that it adds a const attribute that cannot be used to modify elements

Refer to the Array container for more details. The most important difference between a list’s iterator and a vector’s iterator is that it is a bidirectional iterator instead of a random-access iterator. If p1 and p2 are bidirectional iterators, then ++p1, p1++, p1–, p1++, *p1, p1==p2, and p1! = (p2); Do not support P1 [I], P1 -= I, P1 += I, P1 + I, P1 – I, P1 P2, P1 <=p2, P1 >=p2. ,>

Second, the instance

1. Loop through the list elements

i = 0; listIter = listInt.begin(); for (; listIter ! = listInt.end(); listIter++) { std::cout << " sort listInt[" << i++ << "]=" << *listIter << std::endl; }

Other functions are similar to vector and so on, but do not specify how to use them

Note:

1, the list does not support random access, did not provide the subscript operator [] and the at () member function, also did not provide the data () member function 2, front and back () () member function, can be the first element in the list container are obtained respectively and the last element reference form, If we want to access elements elsewhere in the list, we can only use the list iterator. We can also use iterators to change the value of the specified element