Question: Need an Iterator method in C++.. Need begin and end function code and as well as three classes in C++. Please Help. blic: /* class
Need an Iterator method in C++.. Need begin and end function code and as well as three classes in C++. Please Help.blic: /* class iterator { public: iterator(const persistent_vector pv, bool end=false): m_pv(pv), m_index(end?pv.m_size:0) {} // // This operator is used to get the value // that the iterator is currently pointing at // const T& operator *() {
} // // This operator is used to move the iterator // to the next value in the container // iterator& operator ++() } // // This operator is used to compare this // iterator to another one. It is mainly // used to determine when to stop iterating. // bool operator !=(const iterator& other) { } private: // // Store enough information to keep track of where you are // }; // // This returns an iterator pointing to the first element // of the persistent vector. // iterator begin() { return } // // This returns an iterator effectively pointing to the // element _after_ the last element in the persistent // vector. // iterator end() { return } */
Add an iterator capability to the persistent vector Basically, the code int main std vector int v 10, 11, 12, 13, 15, 16, 17, 18 persistent vector pv(V) ersistent vector Eiterator it pv.b while it std:: cout std:: endl ++it return 0 should produce 10 11 12 13 15 16 17 The attached code has placeholders for the methods that you will need to implement, but in short you will need begin0-which returns an iterator pointing to the first element in the persistent vector end() w hic h returns an iterator pointing to one element past the end of the persistent vector And the iterator class (a public internal class) must implement operator 0 which dereferences the iterator (returns the value that it is currently pointing at) operator++0 for moving to the next value inthe persistent vector operator!-0 for comparing iterators (ma nly for terminating iteration)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts

blic: /* class iterator { public: iterator(const persistent_vector pv, bool end=false): m_pv(pv), m_index(end?pv.m_size:0) {} // // This operator is used to get the value // that the iterator is currently pointing at // const T& operator *() {