This is an operation to inert X
into a BinTree
, what confuses me is that why the BST->Left
can not be changed in step①,however, it can be changed in step② or ster③,I think these three steps are all in the function, why there is a difference between them, I will appreciate it if someone could help me!
BinTree Insert( BinTree BST, ElementType X ){
if(!BST){
BST=(BinTree)malloc(sizeof(struct TNode));
BST->Data=X;①
BST->Left=NULL;
BST->Right=NULL;
}else{
if(X<BST->Data){
**BST->Left=**Insert(BST->Left,X);②
}else{
**BST->Right=**Insert(BST->Right,X);③
}
return BST;
}