From: Corentin Lefrere Date: Thu, 18 Dec 2025 12:47:44 +0000 (+0100) Subject: added disorder.c X-Git-Url: https://git.uwuaxy.net/?a=commitdiff_plain;h=83bd9c100647042d699143292465cd50ab1bef97;p=axy%2Fft%2Fpushswap.git added disorder.c --- diff --git a/Makefile b/Makefile index 0cd4823..831306a 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ NAME=push_swap -SRCS=algorithm_complex.c algorithm_leafsort.c algorithm_simple.c cheatalloc.c clist.c closure.c frac.c leaf_sort.c leaf_sort_index.c leaf_sort_parse.c list.c main_pushswap.c op_output.c op_p.c op_parse.c op_r.c op_rr.c op_s.c ops.c ops_count.c ops_optimizer.c ops_stackops.c output.c psval.c slice.c splitsort.c splitsort_final.c splitsort_iter.c splitsort_part.c stack.c stacks.c stacks_get.c +SRCS=algorithm_complex.c algorithm_leafsort.c algorithm_simple.c cheatalloc.c clist.c closure.c disorder.c frac.c leaf_sort.c leaf_sort_index.c leaf_sort_parse.c list.c main_pushswap.c op_output.c op_p.c op_parse.c op_r.c op_rr.c op_s.c ops.c ops_count.c ops_optimizer.c ops_stackops.c output.c psval.c slice.c splitsort.c splitsort_final.c splitsort_iter.c splitsort_part.c stack.c stacks.c stacks_get.c RESSRCS=_res_leaf_sort_lookup.h diff --git a/disorder.c b/disorder.c new file mode 100644 index 0000000..bd19eb1 --- /dev/null +++ b/disorder.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* disorder.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: clefrere +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/12/18 10:15:56 by clefrere #+# #+# */ +/* Updated: 2025/12/18 13:46:37 by clefrere ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "pushswap.h" + +t_frac compute_disorder(const t_stack *a) +{ + t_frac res; + size_t i; + size_t j; + t_clist *current; + t_clist *other; + + current = a->list; + i = 0; + res = frac_new(0, 0); + while (i++ < a->len) + { + other = current->prev; + j = i; + while (j++ < a->len) + { + if (current->val == other->val) + cheatexit(1); + if (current->val > other->val) + res.num++; + res.den++; + } + current = current->prev; + } + return (res); +} diff --git a/pushswap.h b/pushswap.h index e1c2dd2..f816a40 100644 --- a/pushswap.h +++ b/pushswap.h @@ -6,7 +6,7 @@ /* By: clefrere +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/12/02 11:02:44 by agilliar #+# #+# */ -/* Updated: 2025/12/18 13:29:32 by agilliar ### ########.fr */ +/* Updated: 2025/12/18 13:46:31 by clefrere ### ########.fr */ /* */ /* ************************************************************************** */ @@ -180,4 +180,6 @@ t_frac frac_new(size_t num, size_t den); t_frac frac_mul(t_frac lhs, t_frac rhs); bool frac_lte(t_frac lhs, t_frac rhs); +t_frac compute_disorder(const t_stack *a); + #endif