当前位置:网站首页>Binary sort tree (BST)~
Binary sort tree (BST)~
2022-07-26 05:45:00 【[email protected]】
Binary sort tree is also called binary search tree , Binary search tree *️~
- Node type definition
typedef struct BTNode{
int key;
struct BTNode *lchild;
struct BTNode *rchild;
}BTNode;
- Find keywords
BTNode* BTSearch(BTNode *bt,int key){
if(bt==NULL)
return NULL;
else{
if(bt->key==key)
return bt;
else if(bt->key<key)
return search(bt->rchild,key)
else
return search(bt->lchild,key)
}
}
- Insert keywords
int BSTInsert(BTNode *&bt,int key){
if(bt==NULL){
bt=(BTNode *)malloc(sizeof(BTNode));
bt->lchild=b->rchild=NULL;
bt->key=key;
return 1;
)
else{
if(bt->key==key)
return 0;
else if(bt->data<key)
return BSTInsert(bt->rchild,key);
else
return BSTInsert(bt->lchild,key);
}
}
- Construct a binary sort tree
void CreateBST(BTNode *&bt,int key[],int n){
int i;
bt=NULL;
for(i=0;i<n;i++)
BSTInsert(bt,key[i]);
}
- Delete keywords
Three situations :1. Deletion degree is 0 The node of , Delete directly
2. Deletion degree is 1 The node of , Delete the node , Then the left subtree ( Right subtree ) Connected to the parent node where the node is deleted
3. Deletion degree is 2 The node of , Take a step on the left , Go straight to the right . Or Take a step to the right , Go straight to the left
版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/207/202207260542336106.html
边栏推荐
- Hack the box -sql injection fundamentals module detailed Chinese tutorial
- Redis transaction
- No EGL display error resolution
- Autumn move - Preparation Plan
- 为什么LPDDR不能完全代替DDR?
- Hack The Box - Introduction to Networking Module详细讲解中文教程
- Polymer physics test question bank
- SSTI payload and various bypass methods
- 芯片的翻新和造假,人被坑麻了
- Thread三种实现方式 和 Handler的用法
猜你喜欢

金仓数据库 KingbaseES SQL 语言参考手册 (8. 函数(十一))

10. Regular expression matching

IVR在voip电话系统的应用与价值

leetcode-aboutString

Yolov3 preparatory work

Ros2 knowledge: DDS basic knowledge

TZC 1283: simple sort - Comparative sort

Attack and defense world -- easy_ web

Application of canoe XML in test modules

Development projects get twice the result with half the effort, a large collection of open source STM32 driver Libraries
随机推荐
又一开源神器,值得收藏学习!
Mongondb API usage
如何从内存解析的角度理解“数组名实质是一个地址”?
Why can't lpddr completely replace DDR?
柠檬班自动化学习毕竟
Benji Bananas 开启第二季边玩边赚奖励活动,支持使用多张 Benji 通行证!
平衡二叉树(AVL) ~
leetcode-aboutString
高效,可靠,安全的串口通讯开源方案
[cloud native] introduction and use of feign of microservices
Mba-day28 concept of number - exercise questions
The refurbishment and counterfeiting of chips have made people feel numb
STL common template library
金仓数据库 KingbaseES SQL 语言参考手册 (11. SQL语句:ABORT 到 ALTER INDEX)
Yolov3 preparatory work
Is it really hopeless to choose electronic engineering and be discouraged?
Day110.尚医通:Gateway集成、医院排班管理:科室列表、根据日期统计数据、排班详情
Six sixths -- it's a little late and a little shallow
Three implementation methods of thread and the usage of handler
A trick to teach you to easily understand Potter's map