Question: Question 1 in c++ Looking ahead in an STL iterator requires an application of operator++ , which in turn advances the iterator. In some cases

Question 1

in c++

Looking ahead in an STL iterator requires an application of operator++ , which in turn advances the iterator. In some cases looking at the next item in the list, without advancing to it, may be preferable. Write the member function with the declaration const_iterator operator+( int k ) const; to facilitate this in a general case. The binary operator+ returns an iterator that corresponds to k positions ahead of current.

Add reverse iterators to the STL List class implementation. Define reverse_iterator and const_reverse_iterator . Add the methods rbegin and rend to return appropriate reverse iterators representing the position prior to the endmarker and the position that is the header node. Reverse iterators internally reverse the meaning of the ++ and -- operators. You should be able to print a list L in reverse by using the code List::reverse_iterator itr = L.rbegin( ); while( itr != L.rend( ) ) cout << *itr++ << endl;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!