中序线索化二叉树:递归实现

来源:互联网 发布:网络对拟态环境的冲击 编辑:程序博客网 时间:2024/05/29 15:10

template<class T>

void ThreadBinaryTree<T>::InThread(ThreadBinaryTreeNode<T>* root,ThreadBinaryTreeNode<T>* &pre){

if(root==NULL)

return;

//中序线索化左子树

InThread(root->leftchild(),pre);  //左路下降递归

if(root->leftchild()==NULL){

//建立前驱线索

root->left=pre;  //把pre变量内容赋给左边线索

root->iTag=1;  //属性设为线索属性

}

if((pre))&&(pre->rightchild()==NULL)){

//建立后继线索

pre->right=root;

pre->rTag=1;

}

pre=root;

InThread(root->rightchild(),pre);//中序线索化右子树


}

0 0
原创粉丝点击