Practice #1
Coddyの「スタック - データ構造シリーズ #1」コースのレッスン 9/13。
次のチャレンジは、スタックを使用するように設計されています。
Stackデータ構造はすでに用意されています。ぜひ活用してください!
チャレンジ
簡単整数配列 (a) を入力として受け取り、逆順にした配列を返す関数 reverse を作成してください。
この問題を解決するために、提供されている 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;
}