]> Untitled Git - axy/ft/pushswap.git/commitdiff
added disorder.c
authorCorentin Lefrere <clefrere@k0r3p1.42mulhouse.fr>
Thu, 18 Dec 2025 12:47:44 +0000 (13:47 +0100)
committerCorentin Lefrere <clefrere@k0r3p1.42mulhouse.fr>
Thu, 18 Dec 2025 12:47:44 +0000 (13:47 +0100)
Makefile
disorder.c [new file with mode: 0644]
pushswap.h

index 0cd48236749dee7d8f4c0f8155981c6f49ff43c8..831306a8f3c62b0c73277cb131db0d3c971781c9 100644 (file)
--- 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 (file)
index 0000000..bd19eb1
--- /dev/null
@@ -0,0 +1,41 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   disorder.c                                         :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: clefrere <clefrere@student.42.fr>          +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   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);
+}
index e1c2dd21d63e80f553a09d030efb46bd46a4f556..f816a40cd890ca54279fa1ba304a0a2d94b2d4f4 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: clefrere <clefrere@student.42.fr>          +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   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