I have a Red Black tree implemented in c++. It supports the functionality of a STL map. Tree nodes contain keys and the values mapped. I want to write an iterator class for this, but I’m stuck with how to do it. Should I make it an inner class of the Tree class? Can anyone give me some guidelines on how to write it + some resources??
Thank You!!
Sure, read this nice article on writing STL iterators, it might give you the needed overview:
http://www.drdobbs.com/184401417
In general, yes, an inner class is good, because the iterator needs access to your implementation specific tree nodes:
The good thing here is that while the iterator is public, the element can still stay private :). And yes, the code above is STL compilant too!