I am running an InOrder iterator for homework, which means the iterator is progressing like this:
- Visiting the left child
- Visit Node
- Visiting the right child
There are also the following complexity limitations: Moving throughout the tree should be difficult in terms of execution time o (n), where n is the number of nodes in the tree and memory complexity is o (h), where h is the height of the tree.
I tried using this method to implement the advance (++) operator:
Tree<DataT>::_InOrderIterator::operator++()
{
TreeNode* node = this->Node->GetRightChild();
while(node != NULL)
{
advanceStack.Push(node);
node = node->GetLeftChild();
}
node = advanceStack.Pop();
if (node == NULL)
{
node = end;
}
this->Node = node;
return *this;
}
, , . , (-) . , : recedeStack , ++.
, ++ (frontStack in the - operator). , .
, ( )?