C?????????????????BST???????????
????????????????? ???????[ 2016/10/9 13:53:18 ] ?????????????? C????
??????5?????????
//?????????
//????1???????????????0?????????
BiTNode *SearchValue(BiTree T??int x){
if (T == NULL) {
return 0;
}else{
if (x < T->data) {
//????????
SearchValue(T->lChild?? x);
}else if (x > T->data){
//????????
SearchValue(T->rChild?? x);
}else{
//??????
printf("?????????????%p "??T);
return T;
}
}
return NULL;
}
??????6????????
//??????????
BiTree *DeleteValue(BiTree *T??int x){
//???????y??????????y???????
BiTNode *searchNode;
BiTNode *parentNode;
//????????????
searchNode = *T;
parentNode = *T;
while (searchNode->data != x) {
if (searchNode->lChild == NULL && searchNode->rChild == NULL) {
//??????????????????????????????????????????????????
printf("%s??????У????????????????? "??__FUNCTION__);
return T;
}
if (x < searchNode->data) {
parentNode = searchNode;
searchNode = searchNode->lChild;
}else if (x > searchNode->data){
parentNode = searchNode;
searchNode = searchNode->rChild;
}else{
break;
}
}
if (searchNode->lChild == NULL && searchNode->rChild == NULL) {
//???????
if ((*T)->lChild == NULL && (*T)->rChild == NULL) {
//??????
free(*T);
*T = NULL;
}else{
//????????????????????
//????ж????????????????????????????
if (searchNode->data < parentNode->data) {
//??????
parentNode->lChild = NULL;
}else{
//???????
parentNode->rChild = NULL;
}
free(searchNode);
searchNode = NULL;
}
return T;
}
if (searchNode->lChild != NULL && searchNode->rChild == NULL) {
//???????????????????
//???????????????????????????????????;
//????????ж?????????????????????????
if (searchNode->data < parentNode->data) {
//??????
parentNode->lChild = searchNode->lChild;
}else{
//???????
parentNode->rChild = searchNode->lChild;
}
free(searchNode);
searchNode = NULL;
return T;
}
if (searchNode->lChild == NULL && searchNode->rChild != NULL) {
//???????????????????
if (searchNode->data < parentNode->data) {
//??????
parentNode->lChild = searchNode->rChild;
}else{
//???????
parentNode->rChild = searchNode->rChild;
}
free(searchNode);
searchNode = NULL;
return T;
}
if (searchNode->lChild != NULL && searchNode->rChild != NULL) {
//?????????????????????????
/**
* ??????????p???????????????????????????p????y?????y????????????????????????y??????y????????y??????????????????y???????p?????
???????????????????????ú???????????
*/
BiTNode *nextNode;//???????????????
BiTNode *nextParentNode;//????????????????????
nextParentNode = searchNode;
nextNode = searchNode->rChild;
while (nextNode->lChild != NULL) {
nextParentNode = nextNode;
nextNode = nextNode->lChild;
}
//??????ж?nextNode????nextParentNode???????С?????????ж??????????????????????????
if (nextNode->data < nextParentNode->data) {
//??????
nextParentNode->lChild = nextNode->rChild;
}else{
//???????
nextParentNode->rChild = nextNode->rChild;
}
//?????
searchNode->data = nextNode->data;
//????????
free(nextNode);
nextNode = NULL;
return T;
}
return T;
}
??????7?????????
int main(int argc?? const char * argv[]) {
BiTree tree;
//????????????
CreateBinarySearchTree(&tree);
MiddleOrder(tree);
printf(" ");
printf("????????????????");
int searchValue;
scanf("%d"??&searchValue);
SearchValue(tree??searchValue);
printf("????????????????");
int deleteValue;
scanf("%d"??&deleteValue);
DeleteValue(&tree?? deleteValue);
printf("?????????");
PreOrder(tree);
printf(" ?????????");
MiddleOrder(tree);//???????
printf(" ");
return 0;
}
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
C?????????????????????C?????????????C?????????????malloc??realloc????C??????????????8?????????C??????const?????ü?????C?????Ч????????????????C?????????C????д???????????????????????C????????λ?????C??????define???????÷??????C???????pthread???????C???????????????C????λ????ü??????????C???????????????????C?????з????????????????????????C?????????
???·???
??????????????????
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????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????