I am not sure what you are confused about. Pointers? Basic execution
flow? From afar, it looks like you are using some kind of Monte Carlo
programming style - writing down a random sequence of tokens, hoping
that this somehow works and does whatever is needed. This is bound to be
a very tedious method and certainly does not work in C++ where a program
might appear to work correctly and still exhibit Undefined Behavior.
Maybe you should first try a simpler program involving pointers?
Anyway, if stepping through debugger does not help you, write down the
state on the paper (values for the memory slots occupied by p, data,
etc) and step through the code on paper.
> Also does changing begin to this do anything:
> iterator begin(){
> Node* curr = root_;
> if (curr->right_ == nullptr && curr->left_ == nullptr) {
For example, here you dereferenced 'curr'.
> return nullptr;
> }
> if (curr != nullptr) {
And only here you check if it can be dereferenced. See a problem here?
Either the check is in the wrong place or it is not needed.
> while(curr->left_!=nullptr){
> curr = curr->left_;
> }
> }
> return iterator(curr);
> }
> Look I have tried this for at least a few things now and ran through a debugger many times guys. Something is not clicking in my understanding so asking me to run through it with a debugger does not help.
>
This version also has no mention of leftThread or rightThread, which
were apparently needed in the previous version. I have no idea what this
function should do, so I do not know if they are needed or not, but it
sure looks suspicious.
hth
Paavo