{
  "type": "code_options",
  "author": "https://github.com/begeekmyfriend/leetcode",
  "source": "solution.md",
  "exercise_id": "2bb10d9cca474fc09519c3f275b27a15",
  "keywords": "栈,树,深度优先搜索,二叉树",
  "title": "二叉树的中序遍历",
  "desc": [
    {
      "content": "\n<p>给定一个二叉树的根节点 <code>root</code> ，返回它的 <strong>中序</strong> 遍历。</p><p> </p><p><strong>示例 1：</strong></p><img alt=\"\" src=\"https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0094.Binary%20Tree%20Inorder%20Traversal/images/inorder_1.jpg\" 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://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0094.Binary%20Tree%20Inorder%20Traversal/images/inorder_5.jpg\" 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://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0094.Binary%20Tree%20Inorder%20Traversal/images/inorder_4.jpg\" 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>\t<li>树中节点数目在范围 <code>[0, 100]</code> 内</li>\t<li><code>-100 <= Node.val <= 100</code></li></ul><p> </p><p><strong>进阶:</strong> 递归算法很简单，你可以通过迭代算法完成吗？</p>",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "cpp"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ]
  ],
  "template": {
    "content": "#include <stdio.h>\n#include <stdlib.h>\nstruct TreeNode\n{\n\tint val;\n\tstruct TreeNode *left;\n\tstruct TreeNode *right;\n};\nstatic void traverse(struct TreeNode *node, int *result, int *count)\n{\n\tif (node == NULL)\n\t{\n\t\treturn;\n\t}\n\ttraverse(node->left, result, count);\n\tresult[*count] = node->val;\n\t(*count)++;\n\ttraverse(node->right, result, count);\n}\nstatic int *inorderTraversal(struct TreeNode *root, int *returnSize)\n{\n\tif (root == NULL)\n\t{\n\t\t*returnSize = 0;\n\t\treturn NULL;\n\t}\n\tint count = 0;\n\tint *result = malloc(5000 * sizeof(int));\n\ttraverse(root, result, &count);\n\t*returnSize = count;\n\treturn result;\n}\nint main()\n{\n\tint count = 0;\n\tinorderTraversal(NULL, &count);\n\treturn 0;\n}",
    "language": "cpp"
  },
  "node_id": "dailycode-fc5373cfcfb541a1b12ec0dbe29f74cf",
  "license": "csdn.net",
  "created_at": 1637894160,
  "topic_link": "https://bbs.csdn.net/topics/600471010"
}