1.Create a tree using recursion(递归)
Using the function "createtree" to create a tree. The function need three parameters. The basic logic is using recursion method.
You need to create a struction to regular the tree node.
1.1 treenode struction
- the basic construction is showed below:
typedef struct TreeNode
{
char data_capacity;
struct TreeNode* left-child-pointer;
struct TreeNode* right-child-pointer;
}TreeNode;
//the two pointers is used to regulate the address of the child node. You can use it as the node of the list.
//the "char data_capacity" is used to preserve the data in every node.
After you create the struction, you need to save the data into the tree nodes. There, you ususally need to deliver into a container to
deliver the data you need to save. (In order to distinguish the datas which need to be save and the capacities which are used to save the data,
we define the name: data_capacity and data_tosave). Usually, the data_tosave is an array or a string. So, you need using a pointer called "index"
to point to the data which needs to be save -> data_tosave[index] and then index++. And then you use recursion to create the tree.
2.Clued-binary tree(线索化二叉树)
Before you create this binary tree, you should know basic knowledge of this new construction. The traverse of the binary tree usually has three
methods including preOrder(前序遍历), inOrder(中序遍历) and postOrder(后续遍历). The first step is to choose the ways of traversing and arrange
all the nodes in the order they are visited. As for one node in the linear list, the front node is the front_node(前驱) and the behind-node is
"behind-node"(后继). For example, we have read one binary tree and the order is "ABDCE". It has the construction of "B-D-C". The next step is to
create the clue-binary tree. In order to ensure where the pointer point to, we should improve the struction.
-the improved construction is showed below:
typedef struct TreeNode
{
char data_capacity;
struct TreeNode* left-child-pointer;
struct TreeNode* right-child-pointer;
int ltag;
int rtag;
}TreeNode;
There, we add two signs to record if the node which is pointed by the previous node is emppty or not. If is, the valur is "1". We use the previous
clue-binary tree as the example(用前序线索化二叉树作为例子). Firstly, we should judge if the "node->lchlid" or the "node->rchild" has value. If it is,
then the left-pointer points to it. If not, then the left-pointer points to the front-node and the right-pointer points to the behind-node.
(也就是说,将所有的节点按对应的遍历顺序写成一列,然后看二叉树的图形中对应的节点中的左孩子区域和右孩子区域所指向的地方是否为空。若是, 则左孩子区域中的
指针指向前驱,ltag赋值为1,用于说明这个指针指向前驱,而右区域若也指向空,则同理,右指针指向后继,rtag=1。若不是,则就指向对应的子孩子。)
没有合适的资源?快使用搜索试试~ 我知道了~
数据结构:二叉树相关代码
共64个文件
obj:12个
cpp:12个
ipch:12个
需积分: 0 2 下载量 170 浏览量
2023-08-24
13:55:41
上传
评论
收藏 84.61MB ZIP 举报
温馨提示
这只是我学习的时候写的一些关于树的代码,保存一下
资源推荐
资源详情
资源评论
收起资源包目录
Tree.zip (64个子文件)
Tree
Tree
question.cpp 12KB
tree c++.cpp 3KB
Tree.vcxproj.filters 2KB
Binary Search Tree (C++).cpp 3KB
Record.txt 3KB
inOrder-clue tree c++.cpp 774B
AVL.cpp 3KB
clue-tree.cpp 5KB
x64
Debug
vc143.pdb 572KB
tree.obj 1KB
inOrder-clue tree c++.obj 1KB
Tree.log 913B
question.obj 498KB
AVL.obj 1KB
tree c++.obj 1KB
Binary Search Tree (C++).obj 1KB
huffmanTree.obj 1KB
post-clue binary tree.obj 1KB
vc143.idb 283KB
Binary Search Tree.obj 1KB
Clue Binary Tree c++.obj 1KB
Tree.tlog
CL.write.1.tlog 20KB
Cl.items.tlog 1KB
Tree.lastbuildstate 155B
CL.command.1.tlog 8KB
link.command.1.tlog 4KB
link.read.1.tlog 6KB
link.write.1.tlog 2KB
CL.read.1.tlog 17KB
Tree.exe.recipe 287B
clue-tree.obj 1KB
Tree.ilk 2.06MB
previous_clue-binary-tree.obj 1KB
Tree.vcxproj 7KB
Tree.vcxproj.user 168B
Binary Search Tree.cpp 4KB
previous_clue-binary-tree.cpp 4KB
tree.cpp 9KB
WindowsTool.h 8KB
huffmanTree.cpp 4KB
Clue Binary Tree c++.cpp 874B
post-clue binary tree.cpp 6KB
.vs
Tree
v17
Browse.VC.db 11.44MB
.suo 41KB
ipch
AutoPCH
c0084e350fe4d66a
HUFFMANTREE.ipch 37.13MB
f6f4377f5a7ae336
BINARY SEARCH TREE.ipch 37.13MB
135ee87ae44b2d0a
CLUE BINARY TREE C++.ipch 37.13MB
5d9ac7ff2af276a7
CLUE-TREE.ipch 37.13MB
e0c67b985d4c2f64
BINARY SEARCH TREE (C++).ipch 37.13MB
d4c6f58d82fa92af
QUESTION.ipch 37.13MB
a116e75bf956375a
AVL.ipch 37.13MB
e30e732134cf816c
POST-CLUE BINARY TREE.ipch 37.13MB
bd222a2b762fb71
PREVIOUS_CLUE-BINARY-TREE.ipch 37.13MB
b7b97a5e39d76853
TREE.ipch 37.13MB
f7114d0d90e49a48
TREE C++.ipch 37.13MB
ce145ebc0ec86497
INORDER-CLUE TREE C++.ipch 37.13MB
FileContentIndex
read.lock 0B
43593a42-7df8-4595-b446-2e7692f27b37.vsidx 18KB
434dacd3-bcc9-414e-b586-1acd92679241.vsidx 19KB
merges
6fa65b12-a824-4cc1-8df8-98f559ace8dc.vsidx 26KB
3e0321b8-096d-477c-9a61-a2200f122888.vsidx 18KB
x64
Debug
Tree.exe 147KB
Tree.pdb 10.05MB
Tree.sln 1KB
共 64 条
- 1
资源评论
wyd20040303
- 粉丝: 128
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 词向量-中文文本相似度计算-采用text2vec词向量工具进行计算对比.zip
- 521293804316625base(1).apk
- ARP IP地址分类及特殊IP
- 【MySQL补丁】vcredist-x64xz MySQL必备插件
- 基于SG3525芯片PWM控制推挽隔离DCDC电源模块AD09设计硬件(原理图+PCB)工程文件.zip
- Word_20240428_092324.docx
- cloudcc_v1.1.10-release_sign.apk
- 基于javaweb(jsp)实现的图书购物网站,基于JSP(MVC模式)和MySQL的网上图书购物系统
- fhdishfifdsf
- javassm源码上传图片功能
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功