前序遍历
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
/**
* Return an array of size *returnSize.
* Note: The returned array must be malloced, assume caller calls free().
*/
int* preorderTraversal(struct TreeNode* root, int* returnSize) {
int *A(struct TreeNode* , int* ,int* );
int* returnlist;
returnlist=(int*)malloc(sizeof(int)*2000);
A(root,returnSize,returnlist);
return returnlist;
}
int *A(struct TreeNode* root, int* returnSize,int* returnlist)
{
if(root==NULL)
return NULL;
*(returnlist+*returnSize)=root->val;
(*returnSize)++;
A(root->left,returnSize,returnlist);
A(root->right,returnSize,returnlist);
return NULL;
}