/**
- Definition for a binary tree node.
- struct TreeNode {
-
int val;
-
struct TreeNode *left;
-
struct TreeNode *right;
- };
*/
/**
- Note: The returned array must be malloced, assume caller calls free().
*/
typedef struct TreeNode Node;
void InOrder(Node* pRoot,int* pRes,int* index) {
if(pRoot) {
InOrder(pRoot->left,pRes,index);
pRes[*index]=pRoot->val;
(*index)++;
InOrder(pRoot->right,pRes,index);
}
}
int GetTreeSize(Node*pRoot) {
if(NULL==pRoot) {
return 0;
}
return GetTreeSize(pRoot->left)+GetTreeSize(pRoot->right)+1;
}
int* inorderTraversal(struct TreeNode* root, int* returnSize){
returnSize=GetTreeSize(root);
int pRes=(int*)malloc(sizeof(int)*(*returnSize));
if(NULL==pRes)
assert(0);
int index=0;
InOrder(root,pRes,&index);
return pRes;
}