Implementing an iterator over binary tree using C++ 11
Posted
by
user1459339
on Stack Overflow
See other posts from Stack Overflow
or by user1459339
Published on 2012-10-02T03:35:58Z
Indexed on
2012/10/02
3:37 UTC
Read the original article
Hit count: 127
I would like to create an iterator over the binary tree so as to be able to use range-based for loop. I understand I ought to implement the begin() and end() function first.
Begin should probably point to the root. According to the specification, however, the end() functions returns "the element following the last valid element". Which element (node) is that? Would it not be illegal to point to some "invalid" place?
The other thing is the operator++. What is the best way to return "next" element in tree? I just need some advice to begin with this programming.
© Stack Overflow or respective owner