Practice #1
Lesson 9 of 13 in Coddy's Stack - Data Structures Series #1 course.
The next challenges are designed to use stack in them.
The Stack data structure is already provided for you — use it!
Challenge
EasyWrite a function reverse that gets an integer array as input (a) and returns the reversed array.
Use the provided Stack to solve this problem!
Try it yourself
#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;
}