diff --git a/ex4/main.c b/ex4/main.c index 08ba61b28c5d05de838b255c4f161e85a8f63fc5..bbd146c9d57d194fbab426852b3479c3de4bc3e8 100644 --- a/ex4/main.c +++ b/ex4/main.c @@ -1,7 +1,7 @@ /** * @file main.c - * @author Prénom Nom - * @brief Exercice 1 + * @author Florian Burgener + * @brief Exercice 4 * @version 1.0 * @date 2021-12-07 * @@ -9,12 +9,9 @@ * */ -#include <math.h> -#include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> -#include <string.h> #include "stack.h" @@ -22,18 +19,21 @@ int main() { int32_t tab_length = 7; double tab[tab_length]; + // Retrieves the input numbers. for (int32_t i = 0; i < tab_length; i += 1) { double number; scanf("%lf", &number); tab[i] = number; } + // Initialization of the algorithm. int32_t interv[tab_length]; interv[0] = 1; stack s; - stack_init(&s, 1000); + stack_init(&s, tab_length); stack_push(&s, 0); + // For each number in tab. for (int32_t i = 0; i < tab_length; i += 1) { while (true) { int32_t top_value; @@ -46,6 +46,7 @@ int main() { stack_pop(&s, &top_value); } + // Sets interv[i] if (stack_is_empty(s)) { interv[i] = i + 1; } else { @@ -59,6 +60,7 @@ int main() { printf("\n"); + // Displays the interv array. for (int32_t i = 0; i < tab_length; i += 1) { printf("%d\n", interv[i]); }