# 二叉树的中序遍历

<p>给定一个二叉树的根节点 <code>root</code> ，返回它的 <strong>中序</strong> 遍历。</p><p> </p><p><strong>示例 1：</strong></p><img alt="" src="https://img-service.csdnimg.cn/img_convert/7f372b0f54f87384cc6c732b3cddc585.jpeg" style="width: 202px; height: 324px;" /><pre><strong>输入：</strong>root = [1,null,2,3]<strong><br />输出：</strong>[1,3,2]</pre><p><strong>示例 2：</strong></p><pre><strong>输入：</strong>root = []<strong><br />输出：</strong>[]</pre><p><strong>示例 3：</strong></p><pre><strong>输入：</strong>root = [1]<strong><br />输出：</strong>[1]</pre><p><strong>示例 4：</strong></p><img alt="" src="https://img-service.csdnimg.cn/img_convert/31457a9f9368167556ffe0b6327ebc98.jpeg" style="width: 202px; height: 202px;" /><pre><strong>输入：</strong>root = [1,2]<strong><br />输出：</strong>[2,1]</pre><p><strong>示例 5：</strong></p><img alt="" src="https://img-service.csdnimg.cn/img_convert/5a5703522184390ad83f06fad6566364.jpeg" style="width: 202px; height: 202px;" /><pre><strong>输入：</strong>root = [1,null,2]<strong><br />输出：</strong>[1,2]</pre><p> </p><p><strong>提示：</strong></p><ul>	<li>树中节点数目在范围 <code>[0, 100]</code> 内</li>	<li><code>-100 <= Node.val <= 100</code></li></ul><p> </p><p><strong>进阶:</strong> 递归算法很简单，你可以通过迭代算法完成吗？</p>

## template

```cpp
#include <stdio.h>
#include <stdlib.h>
struct TreeNode
{
	int val;
	struct TreeNode *left;
	struct TreeNode *right;
};
static void traverse(struct TreeNode *node, int *result, int *count)
{
	if (node == NULL)
	{
		return;
	}
	traverse(node->left, result, count);
	result[*count] = node->val;
	(*count)++;
	traverse(node->right, result, count);
}
static int *inorderTraversal(struct TreeNode *root, int *returnSize)
{
	if (root == NULL)
	{
		*returnSize = 0;
		return NULL;
	}
	int count = 0;
	int *result = malloc(5000 * sizeof(int));
	traverse(root, result, &count);
	*returnSize = count;
	return result;
}
int main()
{
	int count = 0;
	inorderTraversal(NULL, &count);
	return 0;
}
```

## 答案

```cpp

```

## 选项

### A

```cpp

```

### B

```cpp

```

### C

```cpp

```