C?????????????????BST???????????
????????????????? ???????[ 2016/10/9 13:53:18 ] ?????????????? C????
???????????????????н????????????????????????????????????——???????????Binary Search Tree????????????????(Binary Sort Tree)?????????BST???????????????????£?
????1.???????????????????????????н??????С??????????????
????2.???????????????????????????н??????????????????????
????3.?????????????????????????
??????????????????????????????????????????????С??????????????? https://github.com/chenyufeng1991/BinarySearchTree ??
??????1?????????
typedef int elemType;
typedef struct BTNode{
int data;
struct BTNode *lChild;
struct BTNode *rChild;
}BiTNode??*BiTree;
??????2????????????
???????????????????????????????????????????????????????????????λ?á?
//?????????????
/**
* ????-1??????????????????????????????
*/
int CreateBinarySearchTree(BiTree *T){
printf("??????????????????????????У?
");
int num;
scanf("%d"??&num);
while (num != -1) {
Insert(T??num);
scanf("%d"??&num);
}
printf("%s??????У?????????????????
"??__FUNCTION__);
return 1;
}
??????3????????
//??????
void Insert(BiTree *T??int x){
//?????????????????
BiTNode *pInsert = (BiTNode *)malloc(sizeof(BiTNode));
pInsert->data = x;
pInsert->lChild = NULL;
pInsert->rChild = NULL;
if ((*T) == NULL) {
*T = pInsert;
}
if ((*T)->lChild == NULL && x < (*T)->data) {
(*T)->lChild = pInsert;
}
if ((*T)->rChild == NULL && x > (*T)->data) {
(*T)->rChild = pInsert;
}
//??????
if (x < (*T)->data) {
Insert(&(*T)->lChild?? x);
}
if (x > (*T)->data) {
Insert(&(*T)->rChild?? x);
}
return;
}
??????4??????????????????????
???????????????+?????????????????????????????????????????????????????????????С?????????????????????????????????????????в?????????????
//????????????????
//???????????????????????
void MiddleOrder(BiTree T){
if (T == NULL) {
return;
}else{
MiddleOrder(T->lChild);
printf("%d "??T->data);
MiddleOrder(T->rChild);
}
}
//????????????????
//??????????+??????? ????????????????????????????????
void PreOrder(BiTree T){
if (T == NULL) {
return;
}else{
printf("%d "??T->data);
PreOrder(T->lChild);
PreOrder(T->rChild);
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11