Here is a code snippet for implementing inorder on threaded binary trees.
void ThreadedBTree::inorder() {
ThreadedNode *prev, *p = root;
if (p!= 0 ) {
while (p->left != 0)
p = p->left;
while (p!= 0) {
visit(p);
prev = p;
p = p->right;
if ( p!=0 && prev->successor == 0)
{
while (p->left != 0)
p = p->left;
}
}
}
Here the prev->successor value signifies for nodes which have no right child. I mean if the nodes have no right child then their successor value is set to 1 and correspondingly rightptr is set to their successor node otherwise their it is set to zero.
Sunday, May 16, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment