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

Validation exercice 4

parent d40041b1
No related branches found
No related tags found
No related merge requests found
/**
* @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]);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment