[題目分析]在線索二叉樹上插入結點破壞了與被插入結點的線索因此插入結點時必須修復線索在結點y的右側插入結點x因為是後序線索樹要區分結點y有無左子樹的情況
void TreeInsert(BiTree tyx)//在二叉樹t的結點y的右側插入結點x
{if(y>ltag==) //y有左子女
{p=y>lchild; if (p>rtag==) p>rchild=x; //x是y的左子女的後序後繼
x>ltag=; x>lchild=p; //x的左線索是y的左子女
}
else //y無左子女
{x>ltag=; x>lchild=y>lchild;//y的左線索成為x的左線索
if(y>lchild>rtag==) //若y的後序前驅的右標記為
y>lchild>rchild=x; //則將y的後序前驅的後繼改為x
}
x>rtag=; x>rchild=y; y>rtag=; y>rchild=x; //x作y的右子樹
}//結束 TreeInsert
[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
From:http://tw.wingwit.com/Article/program/sjjg/201311/23694.html