非递归方法,使用指针数组代替栈

int* inorderTraversal(struct TreeNode* root, int* returnSize ) {
    *returnSize=0;
    struct TreeNode* stack[1000];
    struct TreeNode* node=root;
    int head=0;
    int tail=0;
    int k=0;
    int* res=(int*)malloc(sizeof(int)*1000);
    while(node||head!=tail){
        if(node){
            stack[tail++]=node;
            node=node->left;
        }else{
            node=stack[--tail];
            res[k++]=node->val;
            node=node->right;
        }
    }
    *returnSize=k;
    return res;
}