Data structure----two-segment sorting tree

结点结构

/**********Node structure*********/
Typedef struct BTNode
{
Int key;
Struct BTNode *lchild;
Struct BTNode *rchild;
}BiNode,*BiTree;

Find keywords

/******** Find keywords **********/
BiNode* BSTSearch(BiTree bt, int key)
{
If (bt == NULL)
Return NULL;
Else
{
If (key == bt->key)
Printf("find success");
Else if (key < bt->key)
Return BSTSearch(bt->lchild,key);
Else
Return BSTSearch(bt->rchild,key);
}
}

Insert keyword

/********** Insert keyword *********/
Int BSTInsert(BiNode *bt, int key)
{
If (bt == NULL)
{
Bt = (BiNode*) malloc(sizeof(BiNode));
Bt->lchild = bt->rchild = NULL;
Bt->key = key;
Return 1;
}
Else
{
If (key == bt->key) //The keyword already exists in the tree and the insertion failed.
Return 0;
Else if (key < bt->key)
Return BSTInsert(bt->lchild, key);
Else
Return BSTInsert(bt->rchild, key);
}

}