listsstacksand queues iterators some operations on listsmost critically those to insert and remove from the middle of the listrequire the notion of position in the stla position is represented by nested typeiterator in particularfor listthe position is represented by the type list::iteratorfor vectorthe position is represented by class vector::iteratorand so on in describing some methodswe'll simply use iterator as shorthandbut when writing codewe will use the actual nested class name initiallythere are three main issues to addressfirsthow one gets an iteratorsecondwhat operations the iterators themselves can performthirdwhich list adt methods require iterators as parameters getting an iterator for the first issuethe stl lists (and all other stl containersdefine pair of methodsr iterator begin)returns an appropriate iterator representing the first item in the container iterator end)returns an appropriate iterator representing the endmarker in the container ( the position after the last item in the containerthe end method seems little unusualbecause it returns an iterator that is "out-ofbounds to see the ideaconsider the following code typically used to print the items in vector prior to the introduction of range-based for loops in ++ forint ! size)++ cout <vi <endlif we were to rewrite this code using iteratorswe would see natural correspondence with the begin and end methodsforvector::iterator itr begin)itr ! end)itr ??cout <itr ??<endlin the loop termination testboth != sizeand itr!= endare intended to test if the loop counter has become "out-of-bounds the code fragment also brings us to the second issuewhich is that the iterator must have methods associated with it (these unknown methods are represented by ???iterator methods based on the code fragment aboveit is obvious that iterators can be compared with !and ==and likely have copy constructors and operatordefined thusiterators have methodsand many of the methods use operator overloading besides copyingthe most commonly used operations on iterators include the followingr itr+and ++itradvances the iterator itr to the next location both the prefix and postfix forms are allowable