Menu
CoddyTech

练习 #1

Coddy 栈:数据结构系列 #1 课程的第 9 课,共 13 课。

接下来的挑战需要用到栈 。

已经为你提供了 Stack 数据结构,直接使用它吧!

challenge icon

挑战

简单

编写一个函数 reverse,它接收一个整数数组作为输入(a),并返回反转后的数组。

使用提供的 Stack 来解决这个问题!

亲手试试

#include <stdio.h>
#include <stdlib.h>
#include "reverse.h"

int main() {
    int* a = (int*)malloc(sizeof(int) * 1000);
    int aSize = 0;
    int x;
    while (scanf("%d", &x) == 1) {
        a[aSize++] = x;
    }
    int returnSize;
    int* result = reverse(a, aSize, &returnSize);
    for (int i = 0; i < returnSize; i++) {
        printf("%d\n", result[i]);
    }
    free(a);
    return 0;
}

栈:数据结构系列 #1中的所有课

自己练习: C 在线编译器