二叉树知识点整理

本文深入探讨了二叉树的概念,包括满二叉树、完全二叉树和二叉搜索树,并详细讲解了二叉树的递归遍历算法。通过具体实例,如树的子结构判断、二叉树的镜像反转及二叉搜索树的后续遍历数列,文章提供了丰富的编程实践指导。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

概念:

struct BinaryTree

{

int value;

BinaryTree*pright;

BinaryTree*pleft;

}

满二叉树 完全二叉树 二叉搜索树

编程题:

实现二叉树的遍历:

递归的算法实现二叉树的遍历:

题一:树的子结构:

vool hassubtree(BinaryTree *root1,BinaryTree 8root2)

{

bool result=false;

if(root1!=NULL&&root2!=NULL)

{

if(root1->value==root2->value)

{

result=Dosubtree(root1,toot2);

}

if (!result)

{

result=hassubtree(root1->left,root2);

}

if(!result)

{

result=hassubtree(root1->right,root2);

}

return result;

}

}

bool Dosubtree(BinaryTree *root1,BinaryTree 8root2)

{

if(root1->left==root2->left&&root1->right==root2->right)

 return true;

}

2.二叉树的镜像:

void reverse(Binarysearch *root)

{

//判断:

if(root==NULL||root->left==BULL&&root->right==NULL)

{

return;

}

Binarysearch*ptemp=root->left;

root->left=p->right;

p->right=p->temp;

reverse(p->left);

reverse(p->right);

}

3.二叉搜索树的后续遍历数列:

 

转载于:https://www.cnblogs.com/mmziscoming/p/5757115.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值