| Home / Mainframe - DB2 / |
What is a threaded binary tree? |
|
|
Since traversing the three is the most frequent operation, a method must be devised to improve the speed. This is where Threaded tree comes into picture. If the right link of a node in a tree is NULL, it can be replaced by the address of its inorder successor. An extra field called the rthread is used. If rthread is equal to 1, then it means that the right link of the node points to the inorder success. If its equal to 0, then the right link represents an ordinary link connecting the right subtree.
temp = x->right; if(x->rthread==1)return(temp); while(temp->left!=NULL)temp = temp->left; return(temp);
if(head->left==head) temp = head; for(;;) }
Inserting toward the left of a node in a threaded binary tree.
temp=getnode();
temp = x->left; if(x->lthread==1)return(temp); while(temp->right!=NULL) return(temp); |
|
