当前位置:网站首页>Tree search (bintree)
Tree search (bintree)
2022-08-05 01:52:00 【domineering ocean】
介绍
We are in the usual search algorithm,The most are often sequential search and halved search,And the tree search is often half-understood,This article mainly introduces the creation of binary sorting tree,插入和查找.
树的定义
树是一种数据结构,它是由n(n≥0)个有限节点组成一个具有层次关系的集合.把它叫做“树”是因为它看起来像一棵倒挂的树,也就是说它是根朝上,而叶朝下的.它具有以下的特点:
每个节点有零个或多个子节点;没有父节点的节点称为根节点;每一个非根节点有且只有一个父节点;除了根节点外,每个子节点可以分为多个不相交的子树.
If a tree contains at most two subtrees at each node, it is called a binary tree.
The program definition of a binary tree is generally as follows:
typedef char Elemtype ;
typedef struct BiNode
{
Elemtype data;
struct BiNode *lchild,*rchild;
}*BiTree;
二叉排序树的插入
添加一个值为knode to the treeT上.
int BST_inser(BiTree T,Elemtype k)
{
if(T==NULL)
{
T=(BiTree)malloc(sizeof(BiNode));
T->data=k;
T->lchild=NULL;
T->rchild=NULL;
return 1;//插入成功
}
else if(T->data==k)
{
return 0;
}
else if(T->data>k)
{
return BST_inser( T=T->lchild,k);
}
else
{
return BST_inser(T=T->rchild,k);
}
}
二叉排序树的创建
The creation of a binary sorted tree is actually to create an empty tree,Then a set of data is stored in this tree species in turn.
void Creat_BST(BiTree &T,Elemtype a[],int n)
{
T=NULL;//初始时T为空树
int i=0;
while(i<n)
{
BST_inser(T,a[i]);
i++;
}
}
树形查找
Searching a binary sorted tree is actually very simple,is the valuekfrom the root node of the sorted tree,Descending in turn,当kgreater than the current alignmentTnode value,Find this nodeT的右孩子,当ksmaller than the current alignmentTnode value,Find this nodeT的左孩子,When equal to the value of this node,Return this node.
BiNode *Bst_search(BiTree T,Elemtype k)
{
while(T!=NULL&&T->data!=k)
{
if(k<T->data)
T=T->lchild;
else
T=T->rchild;
}
return T;
}
后续
如果想了解更多物联网、智能家居项目知识,可以关注我的项目实战专栏和软硬结合专栏.
欢迎关注公众号了解更多.
编写不易,感谢支持.
边栏推荐
- 程序员失眠时的数羊列表 | 每日趣闻
- Greenplum数据库故障分析——版本升级后gpstart -a为何返回失败
- 从一次数据库误操作开始了解MySQL日志【bin log、redo log、undo log】
- 缺陷检测(图像处理部分)
- Knowledge Points for Network Planning Designers' Morning Questions in November 2021 (Part 2)
- AI+PROTAC|dx/tx完成500万美元种子轮融资
- The use of pytorch: temperature prediction using neural networks
- 短域名绕过及xss相关知识
- EBS利用虚拟列及hint 提示优化sql案例一则
- The difference between a process in user mode and kernel mode [exclusive analysis]
猜你喜欢

pytorch的使用:使用神经网络进行气温预测

手把手基于YOLOv5定制实现FacePose之《YOLO结构解读、YOLO数据格式转换、YOLO过程修改》
![[Machine Learning] 21-day Challenge Study Notes (2)](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[Machine Learning] 21-day Challenge Study Notes (2)

MySQL学习

蓝牙Mesh系统开发四 ble mesh网关节点管理

Interview summary: Why do interviewers in large factories always ask about the underlying principles of Framework?

为什么他们选择和AI恋爱?

优化Feed流遭遇拦路虎,是谁帮百度打破了“内存墙”?

MySQL3

记录谷歌gn编译时碰到的一个错误“I could not find a “.gn“ file ...”
随机推荐
张驰咨询:揭晓六西格玛管理(6 Sigma)长盛不衰的秘密
Live playback including PPT download | Build Online Deep Learning based on Flink & DeepRec
手把手基于YOLOv5定制实现FacePose之《YOLO结构解读、YOLO数据格式转换、YOLO过程修改》
CMS website construction process
软件测试技术之最有效的七大性能测试技术
程序员失眠时的数羊列表 | 每日趣闻
迅睿cms网站搬迁换了服务器后网站不能正常显示
Transfer Learning - Joint Geometrical and Statistical Alignment for Visual Domain Adaptation
How DHCP works
EBS利用虚拟列及hint 提示优化sql案例一则
“嘀哩哩,等灯等灯”,工厂安全生产的提示音
IJCAI2022 | DictBert:采用对比学习的字典描述知识增强的预训练语言模型
短域名绕过及xss相关知识
迁移学习——Distant Domain Transfer Learning
Greenplum数据库故障分析——版本升级后gpstart -a为何返回失败
没有对象的程序员如何过七夕
GCC: paths to header and library files
GCC: compile-time library path and runtime library path
Bit rate vs. resolution, which one is more important?
<开发>实用工具