solution.cpp 682 字节
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#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;
}