原题题目
代码实现
/**
* Definition for a Node.
* struct Node {
* int val;
* int numChildren;
* struct Node** children;
* };
*/
/**
* Note: The returned array must be malloced, assume caller calls free().
*/
#define MAX 11000
void visit(struct Node* root,int* returnSize,int* Array)
{
if(!root)
return;
Array[(*returnSize)++] = root->val;
int i;
for(i=0;i<root->numChildren;i++)
visit(root->children[i],returnSize,Array);
return;
}
int* preorder(struct Node* root, int* returnSize) {
int *Array = (int*)malloc(sizeof(int) * MAX);
*returnSize = 0;
visit(root,returnSize,Array);
return Array;
}