node *Insuc(node *x){
node *temp = x->rchild;
if (x->RightThread == False){ //若x->RightThread為True, temp即找到
while(temp->LeftThread == False)
temp = temp->lchild;
}
return temp;
}
2.2 在引線二元樹中插入一個節點(insert a right child)
void InsertRightChild(node *s, node *t){ //s為樹中節點, t為新節點
t->RightThread = s->RightThread; //設置t的右子點、右引線
t->rchild = s->rchild;
t->LeftThread = True; //設置t的左子點、左引線
t-lchild = s;
s->RightThread = False; //將s連到t
s->rchild = t;
if (s->RightThread == False){ //若s無右子點
node *temp = Insuc(s); //中序排序中s的下一個節點
temp->lchild = t;
}
}
2.3 在引線二元樹中插入一個節點(insert a left child)
void InsertLeftChild(node *s, node *t){ //s為樹中節點, t為新節點
t->LeftThread = s->LeftThread; //設置t的左子點、左引線
t->lchild = s->lchild;
t->RightThread = True; //設置t的右子點、右引線
t-rchild = s;
s->LeftThread = False; //將s連到t
s->lchild = t;
if (s->LeftThread == False){ //若s無左子點
node *temp = Pre(s); //中序排序中s的上一個節點
temp->rchild = t;
}
}
node *Pre(node *x){
node *temp = x->lchild;
if (x->LeftThread == False){ //若x->RightThread為True, temp即找到
while(temp->RightThread == False)
temp = temp->rchild;
}
return temp;
}
void Inorder(node *head){
node *hd = head;
node *temp;
while(temp == hd){
temp = Insuc(head);
head = temp;
}
}