题目描述
![](https://img-blog.csdnimg.cn/054d2ddb2a6c475f91637472a73d7566.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAV2XlsLw=,size_20,color_FFFFFF,t_70,g_se,x_16)
代码实现
/**
* Definition for a Node.
* struct Node {
* int val;
* int numChildren;
* struct Node** children;
* };
*/
/**
* Note: The returned array must be malloced, assume caller calls free().
*/
void dfs(struct Node* root,int* result,int* returnSize)
{
if(root==NULL)
{
return;
}
for(int i=0;i<root->numChildren;i++)
{
dfs(root->children[i],result,returnSize);
}
result[(*returnSize)++]=root->val;
}
int* postorder(struct Node* root, int* returnSize) {
int* result=(int*)malloc(sizeof(int)*10000);
*returnSize=0;
dfs(root,result,returnSize);
return result;
}