Skip to content
Snippets Groups Projects
Commit 95bd3531 authored by Florian Burgener's avatar Florian Burgener
Browse files

Validation exercice 4

parent d40041b1
Branches main
No related tags found
No related merge requests found
/** /**
* @file main.c * @file main.c
* @author Prénom Nom * @author Florian Burgener
* @brief Exercice 1 * @brief Exercice 4
* @version 1.0 * @version 1.0
* @date 2021-12-07 * @date 2021-12-07
* *
...@@ -9,12 +9,9 @@ ...@@ -9,12 +9,9 @@
* *
*/ */
#include <math.h>
#include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include "stack.h" #include "stack.h"
...@@ -22,18 +19,21 @@ int main() { ...@@ -22,18 +19,21 @@ int main() {
int32_t tab_length = 7; int32_t tab_length = 7;
double tab[tab_length]; double tab[tab_length];
// Retrieves the input numbers.
for (int32_t i = 0; i < tab_length; i += 1) { for (int32_t i = 0; i < tab_length; i += 1) {
double number; double number;
scanf("%lf", &number); scanf("%lf", &number);
tab[i] = number; tab[i] = number;
} }
// Initialization of the algorithm.
int32_t interv[tab_length]; int32_t interv[tab_length];
interv[0] = 1; interv[0] = 1;
stack s; stack s;
stack_init(&s, 1000); stack_init(&s, tab_length);
stack_push(&s, 0); stack_push(&s, 0);
// For each number in tab.
for (int32_t i = 0; i < tab_length; i += 1) { for (int32_t i = 0; i < tab_length; i += 1) {
while (true) { while (true) {
int32_t top_value; int32_t top_value;
...@@ -46,6 +46,7 @@ int main() { ...@@ -46,6 +46,7 @@ int main() {
stack_pop(&s, &top_value); stack_pop(&s, &top_value);
} }
// Sets interv[i]
if (stack_is_empty(s)) { if (stack_is_empty(s)) {
interv[i] = i + 1; interv[i] = i + 1;
} else { } else {
...@@ -59,6 +60,7 @@ int main() { ...@@ -59,6 +60,7 @@ int main() {
printf("\n"); printf("\n");
// Displays the interv array.
for (int32_t i = 0; i < tab_length; i += 1) { for (int32_t i = 0; i < tab_length; i += 1) {
printf("%d\n", interv[i]); printf("%d\n", interv[i]);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment