carloscn / carloscn/structstudy

二叉树的层次/前序/中序/后续遍历

Open
#22 4 comments 0 reactions 1 assignee Claimed by @carloscn View on GitHub
Level-middle 二叉树 递归回溯
Dominant language
C
Stars
4
Forks
1
PR merge metrics
No merged PRs in 30d

Description

### 问题描述

https://leetcode.cn/problems/binary-tree-preorder-traversal/
很多问题可以转换为二叉树的结构,然后在二叉树上面进行查找,排序之类的。因此掌握二叉树的遍历(查找)技巧,是解决这类问题的必经之路。二叉树分为分层、前序、中序、后续四种遍历方法。这个小节我们来使用递归进行二叉树的前序遍历。

![image](https://user-images.githubusercontent.com/16836611/187913986-6d1ba0d6-381d-4521-8675-d4d8f274114e.png)

二叉树的中序遍历规则是:**左根右**,上图输出: [8 4 9 2 10 5 1 6 3 7]
二叉树的前序遍历规则是:**根左右**,上图输出: [1 2 4 8 9 5 10 3 6 7]
二叉树的后续遍历规则是:**左右根**,上图输出: [8 9 4 10 5 2 6 7 3 1]
二叉树的层次遍历规则是:**自上下**, 上图输出:[1 2 3 4 5 6 7 8 9 10]

**请创建该二叉树,并编写函数打印二叉树的中序、前序、后续和层次遍历结果**。

### 附录I

通过前序遍历和中序遍历还原二叉树:

演算过程如下,通常就是一步步的找到根节点和左右节点。

![image](https://user-images.githubusercontent.com/16836611/188046720-97a497df-ce17-4aee-aa9e-3c39683528c4.png)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.