# 二叉树的中序遍历

<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

```python
class TreeNode(object):
	def __init__(self, x):
		self.val = x
		self.left = None
		self.right = None
class List2Tree(object):
	def __init__(self, nums: list):
		self.nums = nums
		self.queue = []
		if len(nums) == 1:
			self.root = TreeNode(self.nums.pop(0))
		else:
			a = self.nums.pop(0)
			b = self.nums.pop(0)
			c = self.nums.pop(0)
			self.root = TreeNode(a)
			if b is not None:
				self.root.left = TreeNode(b)
			else:
				self.root.left = b
			if c is not None:
				self.root.right = TreeNode(c)
			else:
				self.root.right = c
			self.queue.append(self.root.left)
			self.queue.append(self.root.right)
	def convert(self):
		while len(self.nums) > 0 and len(self.queue)> 0:
			node = self.queue.pop(0)
			if node is not None:
				num= self.nums.pop(0)
				if num is not None:
					node.left = TreeNode(num)
				else:
					node.left = num
				if len(self.nums) > 0:
					num = self.nums.pop(0)
				else:
					num = None
				if num is not None:
					node.right = TreeNode(num)
				else:
					node.right = num
				self.queue.append(node.left)
				self.queue.append(node.right)
		return self.root
class Solution(object):
	def inorderTraversal(self, root):
		if root is None:
			return []
		root = List2Tree(root).convert()
		res = []
		stack = [root]
		while len(stack) > 0:
			curr = stack.pop()
			if not isinstance(curr, TreeNode):
				res.append(curr)
				continue
			if curr.right is not None:
				stack.append(curr.right)
			stack.append(curr.val)
			if curr.left is not None:
				stack.append(curr.left)
		return res
# %%
s = Solution()
print(s.inorderTraversal(root = [1,None,2,3]))
```

## 答案

```python

```

## 选项

### A

```python

```

### B

```python

```

### C

```python

```