从尾到头打印链表 C语言实现

2020-05-16  本文已影响0人  Summit_yp

从尾到头,首先想到的是递归。

int* reversePrint(struct ListNode* head, int* returnSize)
{
    if(head == NULL){
        *returnSize = 0;
        return malloc(sizeof(int) * 10000);
    }
    int *ans = reversePrint(head->next, returnSize);
    ans[(*returnSize)++] = head->val;
    return ans;
}
上一篇 下一篇

猜你喜欢

热点阅读