Get the value of binary tree nodes by iterators

Hi,

We have a class btree for a C++ binary tree. bt is an object of that class and the class has three member functions (as below) to return a pointer for an iterator in the main function.
1
2
3
beginPreorder();
 beginPostorder();
 beginInorder();


then by increment and dereference we print the values.

For this question, I have thought of a vector to store data in preorder and give its first and last iterators to be sent for the first member function, and another vector for postorder and another for inorder. It's easy.

Do you agree? Or do you have a better way in mind, please?
Last edited on
I don't understand. I don't know what problem you're trying to solve. You say "for this question", but you've never mentioned any questions.
Last edited on
In the binary tree program, we have a class called btree which apparently should contain those above three functions, each returning an iterator to the beginning node in their order. And then in the main function, we must use each of those returned values/iterators to set another iterator for traversing and dereference the values in the related order. How to do that?!

I wanted to use three vectors to firstly save the values in the desired order and then send each vector's begin() and end() iterators for the main() function to be used for traversing the dereference to print data, but it popped up an error:
vector iterator incompatible!:(
Topic archived. No new replies allowed.