Skip to Content
C语言核心技术(原书第2版)
book

C语言核心技术(原书第2版)

by Peter Prinz, Tony Crawford
August 2017
Intermediate to advanced
798 pages
17h 44m
Chinese
China Machine Press
Content preview from C语言核心技术(原书第2版)
动态内存管理
|
195
动态内存管理
12.5 特性
二叉树包含许多节点,每个节点都存储着数据(或者指向数据的指针),它具有以下结
构上的特性:
•
每个节点最多有两个直接的子节点。
•
只有一个被称为根节点的节点,它没有父节点。其他所有的节点都有(且只有)一
个父节点。
•
二叉树中节点的放置规则如下:每个节点值大于或等于其左分支子节点的值,小于
右分支子节点的值。
图
12-1
展示了一个二叉树的结构。
图12-1:一个二叉树
叶节点(
leaf
)是指没有子节点的节点。二叉树的每个节点可看作是其子树(
subtree
)
的根节点,子树包含了它向下继承的所有节点。
二叉树的一个重要属性是它的高度(
height
)。高度是从根到叶最长路径(
path
)的长
度。路径是一个连续的节点链表,它形成了在给定的一对节点之间的连接。路径的长度
就是路径中的节点数量,但不计第一个节点。根据这个定义,只有一个根节点的树,高
度是
0
,而图
12-1
中所示的树,其高度是
3
。
12.6 二叉树的实现
下面介绍的示例使用动态内存管理实现二元搜索树(二叉树)的主要功能函数。这个树
可以用来存放任一类型的数据。因此,节点的结构类型包含弹性的成员以存放数据,以
及用于指示该数据所占空间大小的成员:
typedef struct Node { struct Node *left, //
指向左子节点的指针
*right; //
指向右子节点的指针
size_t size; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

算法精讲视频课程:24篇系列讲座

算法精讲视频课程:24篇系列讲座

罗伯特·塞奇威克, 凯文·韦恩(Kevin Wayne)

Publisher Resources

ISBN: 9787111562207