The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 398 Weeks Ago, 1 Day Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
In our implementation of an iterator for class NodeList in Code Fragment 6.7, we defined only the preincrement operator. Provide a definition for a postincrement operator.
Code Fragment 6.7: Class Iterator, realizing an iterator for a doubly linked list.
Our iterator object is called Iterator. To users of class NodeList, it can be accessed by the qualified type name NodeList::Iterator. Its definition, which is presented in Code Fragment 6.7, is placed in the public part of NodeList. An element associated with an iterator can be accessed by overloading the dereferencing operator (“*”). In order to make it possible to compare iterator objects, we overload the equality and inequality operators (“==” and “!=”). We provide the ability to moveforward or backward in the list by providing the increment and decrement operators(“++” and “– –”). We declare NodeList to be a friend, so that it may access theprivate members of Iterator. The private data member consists of a pointer v to theassociated node of the list. We also provide a private constructor, which initializesthe node pointer. (The constructor is private so that only NodeList is allowed tocreate new iterators.)
class Iterator {// an iterator for the listpublic: Elem& operator*();// reference to the elementbool operator==(const Iterator& p) const;// compare positionsbool operator!=(const Iterator& p) const; Iterator& operator++();// move to next positionIterator& operator−−();// move to previous positionfriend class NodeList;// give NodeList accessprivate: Node* v;// pointer to the nodeIterator(Node* u);// create from node};
Hel-----------lo -----------Sir-----------/Ma-----------dam----------- ----------- -----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------acq-----------uis-----------iti-----------on -----------of -----------my -----------sol-----------uti-----------on.-----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- ca-----------tch-----------