mirror of
https://github.com/DavidGailleton/42-Push_Swap.git
synced 2026-01-27 08:41:58 +00:00
Merge branch 'master' of github.com:DavidGailleton/42-Push_Swap into medium_algo
This commit is contained in:
2
Makefile
2
Makefile
@@ -33,7 +33,7 @@ INSERTION = insertion.c
|
|||||||
FLAGS_FILES = algorithms_sort.c flag.c bench.c
|
FLAGS_FILES = algorithms_sort.c flag.c bench.c
|
||||||
|
|
||||||
PARSING = ft_atoi.c parsing.c ft_strncmp.c ft_split.c ft_strlen.c ft_substr.c checker.c ft_itoa.c ft_isdigit.c \
|
PARSING = ft_atoi.c parsing.c ft_strncmp.c ft_split.c ft_strlen.c ft_substr.c checker.c ft_itoa.c ft_isdigit.c \
|
||||||
ft_strjoin.c ft_strlcat.c ft_strlcpy.c parsing_2.c
|
ft_strjoin.c ft_strlcat.c ft_strlcpy.c parsing_2.c disorder.c
|
||||||
|
|
||||||
CHECKER_FILES = check_error.c verif_flag.c verif_is_digit.c verif_overflow.c verif_double.c
|
CHECKER_FILES = check_error.c verif_flag.c verif_is_digit.c verif_overflow.c verif_double.c
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
|
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2026/01/07 08:03:08 by mteriier #+# #+# */
|
/* Created: 2026/01/07 08:03:08 by mteriier #+# #+# */
|
||||||
/* Updated: 2026/01/08 14:15:37 by dgaillet ### ########lyon.fr */
|
/* Updated: 2026/01/09 11:27:39 by dgaillet ### ########lyon.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -33,5 +33,6 @@ int ft_strlcpy(char *dst, const char *src, int size);
|
|||||||
int ft_strlcat(char *dst, const char *src, int size);
|
int ft_strlcat(char *dst, const char *src, int size);
|
||||||
char *join_all(int argc, char **argv);
|
char *join_all(int argc, char **argv);
|
||||||
char **split_all(char *tab);
|
char **split_all(char *tab);
|
||||||
|
float compute_disorder(char **strs);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
46
parsing/disorder.c
Normal file
46
parsing/disorder.c
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* disorder.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2026/01/09 11:05:37 by dgaillet #+# #+# */
|
||||||
|
/* Updated: 2026/01/09 11:26:24 by dgaillet ### ########lyon.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "push_swap.h"
|
||||||
|
|
||||||
|
static int strs_len(char **strs)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (strs[i])
|
||||||
|
i++;
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
|
||||||
|
float compute_disorder(char **strs)
|
||||||
|
{
|
||||||
|
float mistakes;
|
||||||
|
float total_pairs;
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
mistakes = 0;
|
||||||
|
total_pairs = 0;
|
||||||
|
i = 0;
|
||||||
|
while (i < strs_len(strs))
|
||||||
|
{
|
||||||
|
j = i + 1;
|
||||||
|
while (j < strs_len(strs))
|
||||||
|
{
|
||||||
|
total_pairs += 1;
|
||||||
|
if (strs[i] > strs[j])
|
||||||
|
mistakes += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (mistakes / total_pairs);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user