This is for homework, I have done a few implementations for preorder/levelorder, but am having a difficult time.
iterator is biderectional, using a stack. I understand the process of how tree traversal works but putting it into the correct syntax with a stack is just making me run in circles. Any help or hints is greatly appreciated.
here are implementations..
template < class C >
void PostorderBTIterator<C>::Dump(std::ostream& os, char ofc) const
{
fsu::Stack < Node* , fsu::Vector < Node* > > s(stk_);
fsu::Stack < Node* , fsu::Vector < Node* > > stk;
while (!s.Empty())
{
stk.Push(s.Top());
s.Pop();
}
if (ofc == '\0')
{
while (!stk.Empty())
{
os << stk.Top()->value_;
stk.Pop();
}
}
else
{
while (!stk.Empty())
{
os << ofc << stk.Top()->value_;
stk.Pop();
}
}
os << '\n';
}
template < class C >
void PostorderBTIterator<C>::Init(Node* n)
// only intended to be used with n = root_
{
// implementation required
Node * n;
while (n->IsDead())
Increment();
}
template < class C >
void PostorderBTIterator<C>::Increment()
{
// implementation required
/* what i have currently
if (n->HasLeftChild)
{
++n;
}
else if (n->HasRightChild)
{
n++;
}
else
{
while (n->IsValid())//if no children, go up to parent
{
prev = n;
--n;
if ((prev == n.lchild_) && n->HasRightChild())
{
n++; //find sibling of the root
break;
}
}
}
}
*/
template < class C >
void PostorderBTIterator<C>::rInit(Node* n)
// only intended to be used with n = root_
{
// implementation required
}
template < class C >
void PostorderBTIterator<C>::Decrement()
{
// implementation required
}
template < class C >
PostorderBTIterator<C>& PostorderBTIterator<C>::operator++ ()
{
// implementation required
}
template < class C >
PostorderBTIterator<C> PostorderBTIterator<C>::operator++ (int)
{
// implementation required
}
template < class C >
PostorderBTIterator<C>& PostorderBTIterator<C>::operator-- ()
{
// implementation required
}
template < class C >
PostorderBTIterator<C> PostorderBTIterator<C>::operator-- (int)
{
// implementation required
}
} // namespace fsu
#endif
[code]