From c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:08:27 +0200 Subject: add: graphs et rushs --- graphs/piscine/hill_array/hill_array.c | 43 ++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 graphs/piscine/hill_array/hill_array.c (limited to 'graphs/piscine/hill_array/hill_array.c') diff --git a/graphs/piscine/hill_array/hill_array.c b/graphs/piscine/hill_array/hill_array.c new file mode 100644 index 0000000..14d3a85 --- /dev/null +++ b/graphs/piscine/hill_array/hill_array.c @@ -0,0 +1,43 @@ +#include "hill_array.h" + +int top_of_the_hill(int tab[], size_t len) +{ + if (len == 0) + { + return -1; + } + + int top = 0; + size_t i = 0; + + while (i + 1 < len && tab[i] <= tab[i + 1]) + { + if (tab[i] < 0 || tab[i + 1] < 0) + { + return -1; + } + if (tab[i] != tab[i + 1]) + { + top = i + 1; + } + i++; + } + + while (i + 1 < len && tab[i] >= tab[i + 1]) + { + if (tab[i] < 0 || tab[i + 1] < 0) + { + return -1; + } + i++; + } + + if (i + 1 == len) + { + return top; + } + else + { + return -1; + } +} -- cgit v1.2.3