From 4c83562ca98e752ba2f94da6a6bc82567feb7c4b Mon Sep 17 00:00:00 2001 From: HexPloR Date: Mon, 24 Jun 2024 00:05:59 +0200 Subject: [PATCH] ez --- Makefile | 57 ++++++++ checker_linux | Bin 0 -> 38192 bytes includes/push_swap.h | 87 ++++++++++++ lib/ft_printf/Makefile | 30 ++++ lib/ft_printf/header/ft_printf.h | 31 ++++ lib/ft_printf/source/ft_printf.c | 78 ++++++++++ lib/ft_printf/source/ft_put_unsigned_nbr_fd.c | 29 ++++ lib/ft_printf/source/ft_putchar_fd.c | 18 +++ lib/ft_printf/source/ft_puthex_lower_fd.c | 29 ++++ lib/ft_printf/source/ft_puthex_upper_fd.c | 29 ++++ lib/ft_printf/source/ft_putnbr_fd.c | 29 ++++ lib/ft_printf/source/ft_putptr_fd.c | 32 +++++ lib/ft_printf/source/ft_putstr_fd.c | 33 +++++ lib/libft/Makefile | 31 ++++ lib/libft/ft_atoi.c | 106 ++++++++++++++ lib/libft/ft_bzero.c | 29 ++++ lib/libft/ft_calloc.c | 42 ++++++ lib/libft/ft_isalnum.c | 20 +++ lib/libft/ft_isalpha.c | 21 +++ lib/libft/ft_isascii.c | 20 +++ lib/libft/ft_isdigit.c | 20 +++ lib/libft/ft_isprint.c | 19 +++ lib/libft/ft_itoa.c | 104 ++++++++++++++ lib/libft/ft_memchr.c | 29 ++++ lib/libft/ft_memcmp.c | 37 +++++ lib/libft/ft_memcpy.c | 26 ++++ lib/libft/ft_memmove.c | 40 ++++++ lib/libft/ft_memset.c | 27 ++++ lib/libft/ft_putchar_fd.c | 18 +++ lib/libft/ft_putendl_fd.c | 19 +++ lib/libft/ft_putnbr_fd.c | 87 ++++++++++++ lib/libft/ft_putstr_fd.c | 25 ++++ lib/libft/ft_split.c | 108 ++++++++++++++ lib/libft/ft_strchr.c | 29 ++++ lib/libft/ft_strdup.c | 41 ++++++ lib/libft/ft_striteri.c | 26 ++++ lib/libft/ft_strjoin.c | 28 ++++ lib/libft/ft_strlcat.c | 40 ++++++ lib/libft/ft_strlcpy.c | 43 ++++++ lib/libft/ft_strlen.c | 22 +++ lib/libft/ft_strmapi.c | 31 ++++ lib/libft/ft_strncmp.c | 28 ++++ lib/libft/ft_strnstr.c | 46 ++++++ lib/libft/ft_strrchr.c | 34 +++++ lib/libft/ft_strtrim.c | 27 ++++ lib/libft/ft_substr.c | 47 ++++++ lib/libft/ft_tolower.c | 20 +++ lib/libft/ft_toupper.c | 20 +++ lib/libft/libft.h | 88 ++++++++++++ src/.find_last.c.swp | Bin 0 -> 12288 bytes src/.find_max.c.swp | Bin 0 -> 12288 bytes src/.find_min.c.swp | Bin 0 -> 12288 bytes src/assign_param_list.c | 25 ++++ src/big_sort.c | 91 ++++++++++++ src/condition.c | 36 +++++ src/find_last.c | 24 ++++ src/find_lower_rank.c | 51 +++++++ src/find_max.c | 30 ++++ src/find_min.c | 30 ++++ src/find_moyenne.c | 30 ++++ src/find_quicker.c | 134 ++++++++++++++++++ src/free_stack.c | 40 ++++++ src/ft_list_find.c | 28 ++++ src/ft_list_push_back.c | 38 +++++ src/is_sorted.c | 30 ++++ src/list_index.c | 27 ++++ src/list_lenght.c | 29 ++++ src/main.c | 82 +++++++++++ src/normal_trie.c | 56 ++++++++ src/parse_arg.c | 82 +++++++++++ src/parse_args.c | 26 ++++ src/push.c | 47 ++++++ src/push_two_number.c | 20 +++ src/reverse_rotate.c | 40 ++++++ src/rotate.c | 37 +++++ src/set_precedant.c | 33 +++++ src/sort_3.c | 59 ++++++++ src/sort_4.c | 46 ++++++ src/sort_5.c | 41 ++++++ src/swap.c | 36 +++++ src/turc.c | 100 +++++++++++++ 81 files changed, 3228 insertions(+) create mode 100644 Makefile create mode 100755 checker_linux create mode 100644 includes/push_swap.h create mode 100755 lib/ft_printf/Makefile create mode 100755 lib/ft_printf/header/ft_printf.h create mode 100755 lib/ft_printf/source/ft_printf.c create mode 100755 lib/ft_printf/source/ft_put_unsigned_nbr_fd.c create mode 100755 lib/ft_printf/source/ft_putchar_fd.c create mode 100755 lib/ft_printf/source/ft_puthex_lower_fd.c create mode 100755 lib/ft_printf/source/ft_puthex_upper_fd.c create mode 100755 lib/ft_printf/source/ft_putnbr_fd.c create mode 100755 lib/ft_printf/source/ft_putptr_fd.c create mode 100755 lib/ft_printf/source/ft_putstr_fd.c create mode 100755 lib/libft/Makefile create mode 100755 lib/libft/ft_atoi.c create mode 100755 lib/libft/ft_bzero.c create mode 100755 lib/libft/ft_calloc.c create mode 100755 lib/libft/ft_isalnum.c create mode 100755 lib/libft/ft_isalpha.c create mode 100755 lib/libft/ft_isascii.c create mode 100755 lib/libft/ft_isdigit.c create mode 100755 lib/libft/ft_isprint.c create mode 100755 lib/libft/ft_itoa.c create mode 100755 lib/libft/ft_memchr.c create mode 100755 lib/libft/ft_memcmp.c create mode 100755 lib/libft/ft_memcpy.c create mode 100755 lib/libft/ft_memmove.c create mode 100755 lib/libft/ft_memset.c create mode 100755 lib/libft/ft_putchar_fd.c create mode 100755 lib/libft/ft_putendl_fd.c create mode 100755 lib/libft/ft_putnbr_fd.c create mode 100755 lib/libft/ft_putstr_fd.c create mode 100755 lib/libft/ft_split.c create mode 100755 lib/libft/ft_strchr.c create mode 100755 lib/libft/ft_strdup.c create mode 100755 lib/libft/ft_striteri.c create mode 100755 lib/libft/ft_strjoin.c create mode 100755 lib/libft/ft_strlcat.c create mode 100755 lib/libft/ft_strlcpy.c create mode 100755 lib/libft/ft_strlen.c create mode 100755 lib/libft/ft_strmapi.c create mode 100755 lib/libft/ft_strncmp.c create mode 100755 lib/libft/ft_strnstr.c create mode 100755 lib/libft/ft_strrchr.c create mode 100755 lib/libft/ft_strtrim.c create mode 100755 lib/libft/ft_substr.c create mode 100755 lib/libft/ft_tolower.c create mode 100755 lib/libft/ft_toupper.c create mode 100755 lib/libft/libft.h create mode 100644 src/.find_last.c.swp create mode 100644 src/.find_max.c.swp create mode 100644 src/.find_min.c.swp create mode 100644 src/assign_param_list.c create mode 100644 src/big_sort.c create mode 100644 src/condition.c create mode 100644 src/find_last.c create mode 100644 src/find_lower_rank.c create mode 100644 src/find_max.c create mode 100644 src/find_min.c create mode 100644 src/find_moyenne.c create mode 100644 src/find_quicker.c create mode 100644 src/free_stack.c create mode 100644 src/ft_list_find.c create mode 100644 src/ft_list_push_back.c create mode 100644 src/is_sorted.c create mode 100644 src/list_index.c create mode 100644 src/list_lenght.c create mode 100644 src/main.c create mode 100644 src/normal_trie.c create mode 100644 src/parse_arg.c create mode 100644 src/parse_args.c create mode 100644 src/push.c create mode 100644 src/push_two_number.c create mode 100644 src/reverse_rotate.c create mode 100644 src/rotate.c create mode 100644 src/set_precedant.c create mode 100644 src/sort_3.c create mode 100644 src/sort_4.c create mode 100644 src/sort_5.c create mode 100644 src/swap.c create mode 100644 src/turc.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..51a3fa2 --- /dev/null +++ b/Makefile @@ -0,0 +1,57 @@ +NAME = push_swap + +DIR_OBJ = obj +OBJ = $(addprefix $(DIR_OBJ)/,*.o) + +DIR_SRC = src +SRC = $(addprefix $(DIR_SRC)/,*.c) + +FLAGS = -Werror -Wall -Wextra -g +CC = cc + +DIR_LIB = lib + +DIR_PRINTF = $(addprefix $(DIR_LIB)/,ft_printf) +FT_PRINTF_LIB = libftprintf.a +FT_PRINTF = $(addprefix $(DIR_PRINTF)/,$(FT_PRINTF_LIB)) + +DIR_LIBFT = $(addprefix $(DIR_LIB)/,libft) +LIBFT_LIB = libft.a +LIBFT = $(addprefix $(DIR_LIBFT)/,$(LIBFT_LIB)) + +$(NAME): $(OBJ) $(FT_PRINTF) $(LIBFT) + $(CC) $(OBJ) -o $(NAME) $(FT_PRINTF) $(LIBFT) + +$(OBJ): $(DIR_OBJ) $(SRC) + $(CC) -c $(FLAGS) $(SRC) + @mv *.o $(DIR_OBJ) + +$(FT_PRINTF): + make -C $(DIR_PRINTF) + +$(LIBFT): + make -C $(DIR_LIBFT) + +$(DIR_OBJ): + @mkdir -p $(DIR_OBJ) + +all: $(NAME) $(FT_PRINTF) $(LIBFT) + make -C $(DIR_PRINTF) + make -C $(DIR_LIBFT) + +clean: + rm -rf $(DIR_OBJ) + make clean -C $(DIR_PRINTF) + make clean -C $(DIR_LIBFT) + +fclean: clean + rm $(NAME) + make fclean -C $(DIR_PRINTF) + make fclean -C $(DIR_LIBFT) + +re: fclean all + +run: + ./push_swap + +.PHONY: all re fclean clean run diff --git a/checker_linux b/checker_linux new file mode 100755 index 0000000000000000000000000000000000000000..002d5930236c65f1a695bf2fe08489bec0c49745 GIT binary patch literal 38192 zcmeHwdwi7D(f_ka5JVtBK~Ygw1q6kNNHA281Xx@!(MXBn1(!{-Kx%F#y9$~Bz9H6i zS;f}(S8S>Ety-;@dZ}8f2;owKzNit=MvFCStQ!|KZD~zw%KpAHXU=ok>|*=AzyE&S z4`iNaX3m^BbLPyMbJ=9Ar)YkL%Vp?Krg5=BZx0-!Fa<*BiOK^&fst<`@@~Zsl zlc!J1ZK%zi%Izlk#CyqQrCbxKtxZchkHCMz5&euoe=I(A_{{fzGUvfFo9=w?cjJHZ z=WHNS)%zph-O0>&&&7YLJNZMlI^Gy&TqRbi*9_>Va_W}pMxegFw%+jh8iM}v8+_#} zZ}2VmS5_JI0e^*2?XRk;EeElDmEX6#vc_Lkc}oDVRGJFZ2YuE4${OS5`pRIySY96p z7?%_+m^0TmHFui%G&MKR@GV$e?5haW2Ub)z1OxSpi|1C=)&v&&%c@A+it5@L5$98^ zDH)+V^?wFDBtxF)jeNl+Q2XzQ%F3bSN!NfzxX>w;#}aP^p6R2-UaYg{Lt_y6I1+4R0TRF&kb)bCDh!9*UZuUK@U}i8YL;1y3@l{ra=T zhL@1Qq*fbV#|9$owc+jYv)zW*Z6^%^86MxKZ=hqK4bBg(89cq#Qp z2b>S+ozd$Je-bZ^-es3^4=Xs zGQHs*?~d4PuWOI@%_G545crG;96|!q$y+z;=U_8J=XslFeV3j}NuMF!$gDf@78{Bt z$GrHlXTWWEcab{lNU=Zff=IN7*q3%M2M0Z&SE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!IX=~+!gSU+#n`rBbRb9 zFx7IL&JC=T>}zEOgy=U_RHb36gnmX1{_4td=tN;Y7X!k`MG9Drv`+HN|1CHb0%!{Z z%VGZL^IZ+~Jpv&!uYM+Y7XD-DWR}+zrNp~p)Nl_%46B!_|S6fIQ-Y;TjfDRx9sm=S;1}B1KCuU?-T=T z*eZ;={^a(rm-2IjPoJY}sP}cL{E7IVT>dWL$R?y8ee`*|hO!J*MEn%>%=a*!?B(^j zyoSq6PW6x@?;75VcYFDbqKJlCUoA$zYxv`&@_OG$!~L@VugmLt_4|WK<@J344Y90r ze3IM$b1AR;PwyLQ7|{fgqV?87pGhh|G>vs*`1{-bd>GJv{D&w@U9QXP`wx#w`5tN%@RoUUK*tK|HX z<^O`RRR0wGw|{i`iFPEO#T*W(``*r4AoZ_2L1Ag0A=lFS>$pb#t#wzN>gS`)3eF=2 Z+eg>0QN!_&s{El1isOi86qsE8{{pOBm#zQ+ literal 0 HcmV?d00001 diff --git a/includes/push_swap.h b/includes/push_swap.h new file mode 100644 index 0000000..35a61fc --- /dev/null +++ b/includes/push_swap.h @@ -0,0 +1,87 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* push_swap.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/02/26 16:42:02 by yantoine #+# #+# */ +/* Updated: 2024/03/23 23:04:24 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#ifndef PUSH_SWAP_H +# define PUSH_SWAP_H +# include "../lib/ft_printf/header/ft_printf.h" +# include "../lib/libft/libft.h" + +typedef struct Element +{ + struct Element *suivant; + struct Element *precedant; + struct Element *precedant_boucle; + int index; + int instruction; + int instruction_ra; + int instruction_rb; + int instruction_rab; + int wich_instr; + int ptr_num; + long number; +} t_Element; + +typedef struct Liste +{ + t_Element *premier; + t_Element *dernier; + t_Element *lower_rank; + int max; + int min; + int length; + int moyenne; +} t_Liste; + +void set_precedant(t_Liste *liste); +void find_quicker(t_Liste *stack_a, t_Liste *stack_b); +void turc(t_Liste *stack_a, t_Liste *stack_b); +void push_two_number(t_Liste *stack_a, t_Liste *stack_b); +void find_moyenne(t_Liste *liste); +void sort_3(t_Liste *stack_a); +void sort_4(t_Liste *stack_a, t_Liste *stack_b); +void sort_5(t_Liste *stack_a, t_Liste *stack_b); +void big_sort(t_Liste *stack_a, t_Liste *stack_b); +void ft_list_push_back(t_Liste *liste, int valeur); + +void normal_trie(t_Liste *stack_a, t_Liste *stack_b); +void reverse_a_trie(t_Liste *stack_a, t_Liste *stack_b); +void reverse_b_trie(t_Liste *stack_a, t_Liste *stack_b); +void reverse_ab_trie(t_Liste *stack_a, t_Liste *stack_b); + +void swap(t_Liste *liste, char c); +void swap_both(t_Liste *stack_a, t_Liste *stack_b); +void push(t_Liste *stack_a, t_Liste *stack_b, char c); +void rotate(t_Liste *liste, char c); +void rotate_both(t_Liste *stack_a, t_Liste *stack_b); +void reverse_rotate(t_Liste *liste, char c); +void reverse_rotate_both(t_Liste *stack_a, t_Liste *stack_b); + +void free_stack(t_Liste *stack_a, t_Liste *stack_b); +void list_lenght(t_Liste *liste); +void find_max(t_Liste *liste); +void find_min(t_Liste *liste); +void find_last(t_Liste *liste); +void assign_param_list(t_Liste *liste); +void print_stacks(t_Liste *stack_a, t_Liste *stack_b); +void list_index(t_Liste *liste); +void super_algo(t_Liste *stack_a, t_Liste *stack_b); +void find_lower_rank(t_Liste *stack); + +int condition(t_Element *actuel_a, t_Element *actuel_b, \ + t_Liste *stack_b); +int check_following(t_Liste *stack); +int parse_arg(t_Liste *stack_a, char *arg); +int parse_args(t_Liste *stack_a, int argc, char **argv); +int is_sorted(t_Liste *liste); + +t_Element *ft_list_find(t_Liste *liste, int nb); + +#endif diff --git a/lib/ft_printf/Makefile b/lib/ft_printf/Makefile new file mode 100755 index 0000000..17a88e6 --- /dev/null +++ b/lib/ft_printf/Makefile @@ -0,0 +1,30 @@ +NAME = libftprintf.a +CC = cc +CFLAGS = -Wall -Wextra -Werror -c -I$(HEADER_DIR) -g3 +RM = rm -f +AR = ar rcs +SOURCES = ft_printf.c ft_putchar_fd.c ft_putnbr_fd.c ft_putptr_fd.c ft_put_unsigned_nbr_fd.c ft_puthex_upper_fd.c ft_puthex_lower_fd.c ft_putstr_fd.c +SOURCES_DIR = source/ +HEADER = ft_printf.h +HEADER_DIR = header/ +OBJECTS = $(addprefix $(SOURCES_DIR), $(SOURCES:.c=.o)) + +all: $(NAME) + +$(NAME): $(OBJECTS) + $(AR) $(NAME) $(OBJECTS) + +$(OBJECTS): $(SOURCES_DIR)%.o :$(SOURCES_DIR)%.c + $(CC) $(CFLAGS) $< -o $@ + +clean: + $(RM) $(OBJECTS) + +fclean: clean + $(RM) $(NAME) + +re: fclean + @make all + +.PHONY: all clean fclean re + diff --git a/lib/ft_printf/header/ft_printf.h b/lib/ft_printf/header/ft_printf.h new file mode 100755 index 0000000..19ef898 --- /dev/null +++ b/lib/ft_printf/header/ft_printf.h @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_printf.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/12/22 10:18:58 by yantoine #+# #+# */ +/* Updated: 2023/12/26 16:09:17 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_PRINTF_H +# define FT_PRINTF_H + +# include +# include +# include +# include +# include + +int pf_puthex_lower_fd(unsigned int n, int fd); +int pf_puthex_upper_fd(unsigned int n, int fd); +int ft_printf(const char *format, ...); +int pf_putchar_fd(char c, int fd); +int pf_putstr_fd(char *s, int fd); +int pf_putnbr_fd(long int n, int fd); +int pf_put_unsigned_nbr_fd(unsigned int n, int fd); +int pf_putptr_fd(unsigned long long n, int fd); + +#endif diff --git a/lib/ft_printf/source/ft_printf.c b/lib/ft_printf/source/ft_printf.c new file mode 100755 index 0000000..f4a7052 --- /dev/null +++ b/lib/ft_printf/source/ft_printf.c @@ -0,0 +1,78 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_printf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/29 19:11:52 by hexplor #+# #+# */ +/* Updated: 2023/12/26 16:06:47 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../header/ft_printf.h" + +static int ft_ptr_format(va_list parameters_info) +{ + unsigned long long ptr_check; + int count; + + count = 0; + ptr_check = va_arg(parameters_info, unsigned long long); + if (ptr_check == 0) + count += pf_putstr_fd("(nil)", 1); + else + { + count += pf_putstr_fd("0x", 1); + count += pf_putptr_fd(ptr_check, 1); + } + return (count); +} + +static int ft_format_c(char s, va_list parameters_info) +{ + int count; + + count = 0; + if (s == 'c') + count += pf_putchar_fd(va_arg(parameters_info, int), 1); + else if (s == 'i' || s == 'd') + count += pf_putnbr_fd(va_arg(parameters_info, long), 1); + else if (s == 'u') + count += pf_put_unsigned_nbr_fd(va_arg(parameters_info, \ + unsigned int), 1); + else if (s == 's') + count += pf_putstr_fd(va_arg(parameters_info, char *), 1); + else if (s == 'x') + count += pf_puthex_lower_fd(va_arg(parameters_info, long), 1); + else if (s == 'X') + count += pf_puthex_upper_fd(va_arg(parameters_info, long), 1); + else if (s == 'p') + count += ft_ptr_format(parameters_info); + else if (s == '%') + count += pf_putchar_fd('%', 1); + return (count); +} + +int ft_printf(const char *s, ...) +{ + va_list parameters_info; + unsigned int index; + int count; + + index = 0; + count = 0; + va_start(parameters_info, s); + while (s[index]) + { + if (s[index] == '%') + { + index++; + count += ft_format_c(s[index], parameters_info); + } + else if (s[index] != '%' && s[index]) + count += pf_putchar_fd(s[index], 1); + index++; + } + va_end(parameters_info); + return (count); +} diff --git a/lib/ft_printf/source/ft_put_unsigned_nbr_fd.c b/lib/ft_printf/source/ft_put_unsigned_nbr_fd.c new file mode 100755 index 0000000..c808b54 --- /dev/null +++ b/lib/ft_printf/source/ft_put_unsigned_nbr_fd.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_put_unsigned_nbr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/12/02 23:56:02 by hexplor #+# #+# */ +/* Updated: 2023/12/26 15:23:28 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../header/ft_printf.h" + +int pf_put_unsigned_nbr_fd(unsigned int n, int fd) +{ + int count; + + count = 0; + if (n >= 10) + { + count += pf_put_unsigned_nbr_fd(n / 10, fd); + count += pf_put_unsigned_nbr_fd(n % 10, fd); + } + else + { + count += pf_putchar_fd(n + '0', fd); + } + return (count); +} diff --git a/lib/ft_printf/source/ft_putchar_fd.c b/lib/ft_printf/source/ft_putchar_fd.c new file mode 100755 index 0000000..f7aaf34 --- /dev/null +++ b/lib/ft_printf/source/ft_putchar_fd.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/23 14:08:31 by hexplor #+# #+# */ +/* Updated: 2023/12/26 15:23:41 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../header/ft_printf.h" + +int pf_putchar_fd(char c, int fd) +{ + write(fd, &c, 1); + return (1); +} diff --git a/lib/ft_printf/source/ft_puthex_lower_fd.c b/lib/ft_printf/source/ft_puthex_lower_fd.c new file mode 100755 index 0000000..674c37d --- /dev/null +++ b/lib/ft_printf/source/ft_puthex_lower_fd.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_puthex_lower_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/12/02 15:23:28 by hexplor #+# #+# */ +/* Updated: 2023/12/26 15:24:01 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../header/ft_printf.h" + +int pf_puthex_lower_fd(unsigned int n, int fd) +{ + int i; + char *hex; + + i = 0; + hex = "0123456789abcdef"; + if (n >= 16) + { + i += pf_puthex_lower_fd(n / 16, fd); + i += pf_puthex_lower_fd(n % 16, fd); + } + else + i += pf_putchar_fd(hex[n], fd); + return (i); +} diff --git a/lib/ft_printf/source/ft_puthex_upper_fd.c b/lib/ft_printf/source/ft_puthex_upper_fd.c new file mode 100755 index 0000000..d6a6d05 --- /dev/null +++ b/lib/ft_printf/source/ft_puthex_upper_fd.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_puthex_upper_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/12/02 15:27:12 by hexplor #+# #+# */ +/* Updated: 2023/12/26 15:24:21 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../header/ft_printf.h" + +int pf_puthex_upper_fd(unsigned int n, int fd) +{ + int i; + char *hex; + + i = 0; + hex = "0123456789ABCDEF"; + if (n >= 16) + { + i += pf_puthex_upper_fd(n / 16, fd); + i += pf_puthex_upper_fd(n % 16, fd); + } + else + i += pf_putchar_fd(hex[n], fd); + return (i); +} diff --git a/lib/ft_printf/source/ft_putnbr_fd.c b/lib/ft_printf/source/ft_putnbr_fd.c new file mode 100755 index 0000000..6a51f3e --- /dev/null +++ b/lib/ft_printf/source/ft_putnbr_fd.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/12/01 23:41:52 by hexplor #+# #+# */ +/* Updated: 2023/12/26 15:24:42 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../header/ft_printf.h" + +int pf_putnbr_fd(long int n, int fd) +{ + int count; + + count = 0; + if (n < 0) + { + n = -n; + count += pf_putchar_fd('-', fd); + } + if ((n / 10) > 0) + count += pf_putnbr_fd(n / 10, fd); + pf_putchar_fd((n % 10) + 48, fd); + return (count + 1); +} diff --git a/lib/ft_printf/source/ft_putptr_fd.c b/lib/ft_printf/source/ft_putptr_fd.c new file mode 100755 index 0000000..09139bb --- /dev/null +++ b/lib/ft_printf/source/ft_putptr_fd.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putptr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/12/02 15:14:08 by hexplor #+# #+# */ +/* Updated: 2023/12/26 15:25:02 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../header/ft_printf.h" + +int pf_putptr_fd(unsigned long long n, int fd) +{ + int len; + + len = 0; + if (n >= 16) + { + len += pf_putptr_fd(n / 16, fd); + len += pf_putptr_fd(n % 16, fd); + } + else + { + if (n < 10) + len += pf_putchar_fd(n + '0', fd); + else + len += pf_putchar_fd(n + 'a' - 10, fd); + } + return (len); +} diff --git a/lib/ft_printf/source/ft_putstr_fd.c b/lib/ft_printf/source/ft_putstr_fd.c new file mode 100755 index 0000000..12f4fb9 --- /dev/null +++ b/lib/ft_printf/source/ft_putstr_fd.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/23 14:24:20 by hexplor #+# #+# */ +/* Updated: 2023/12/26 15:25:19 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../header/ft_printf.h" + +int pf_putstr_fd(char *s, int fd) +{ + unsigned int i; + int count; + + if (!s) + { + pf_putstr_fd("(null)", fd); + return (6); + } + i = 0; + count = 0; + while (*(s + i)) + { + count += pf_putchar_fd(*(s + i), fd); + i++; + } + return (count); +} diff --git a/lib/libft/Makefile b/lib/libft/Makefile new file mode 100755 index 0000000..77d0b84 --- /dev/null +++ b/lib/libft/Makefile @@ -0,0 +1,31 @@ +SOURCES = ft_putnbr_fd.c ft_putendl_fd.c ft_putstr_fd.c ft_putchar_fd.c ft_striteri.c ft_strmapi.c ft_itoa.c ft_split.c ft_strtrim.c ft_strjoin.c ft_substr.c ft_strdup.c ft_calloc.c ft_atoi.c ft_strnstr.c ft_memcmp.c ft_memchr.c ft_strncmp.c ft_strrchr.c ft_strchr.c ft_tolower.c ft_toupper.c ft_strlcpy.c ft_strlen.c ft_isprint.c ft_strlcat.c ft_memmove.c ft_memcpy.c ft_bzero.c ft_isalpha.c ft_isdigit.c ft_memset.c ft_isalnum.c ft_isascii.c + +OBJECTS = $(SOURCES:.c=.o) + +EXTRA = a.out a.out.dSYM main.c + +NAME = libft.a + +COMPILER = cc + +FLAGS = -c -Wall -Werror -Wextra -I -g3 + +all : $(NAME) + +$(NAME) : $(OBJECTS) + @ar -rcs libft.a *.o + +$(OBJECTS) : $(SOURCES) + $(COMPILER) $(FLAGS) $(SOURCES) + +clean : + @rm -f $(OBJECTS) + +fclean : clean + @rm -rf $(NAME) $(EXTRA) + +re : + @make fclean + @make all + +.PHONY: fclean clean all re diff --git a/lib/libft/ft_atoi.c b/lib/libft/ft_atoi.c new file mode 100755 index 0000000..0c58134 --- /dev/null +++ b/lib/libft/ft_atoi.c @@ -0,0 +1,106 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/13 15:57:24 by hexplor #+# #+# */ +/* Updated: 2024/04/26 15:06:06 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static int ft_isspace(char c) +{ + if (c == '\t' || c == '\n' || c == '\v' \ + || c == '\f' || c == '\r' || c == ' ') + return (1); + return (0); +} + +static int ft_fsign(char c) +{ + if (c == '-') + return (-1); + return (1); +} + +long ft_atoi(const char *text) +{ + long sign; + long number; + + number = 0; + sign = 1; + while (ft_isspace(*text) == 1) + text++; + if (*text == '-' || *text == '+') + { + sign = ft_fsign(*text); + text++; + } + while (ft_isdigit(*text) == 1) + { + number *= 10; + number += *text - '0'; + text++; + } + return (sign * number); +} +/* +#include +#include +int main(void) +{ + + char *texte1 = "12"; + char *texte2 = "+12"; + char *texte3 = "-12"; + + char *texte4 = " \t\n\v\f\r12"; + char *texte5 = " \t\n\v\f\r+12"; + char *texte6 = " \t\n\v\f\r-12"; + + char *texte7 = "--12"; + char *texte8 = "++12"; + char *texte9 = "abcd7"; + + char *texte10 = "12abs"; + char *texte11 = ""; + char *texte12 = "0"; + char *texte13 = "-2147483649"; + char *texte14 = "2147483649"; + + if (ft_atoi(texte1) != 12) + printf("1: NON\n"); + if(ft_atoi(texte2) != 12) + printf("2: NON\n"); + if(ft_atoi(texte3) != -12) + printf("3: NON\n"); + if(ft_atoi(texte4) != 12) + printf("4: NON\n"); + if(ft_atoi(texte5) != 12) + printf("5: NON\n"); + if(ft_atoi(texte6) != -12) + printf("6: NON\n"); + if(ft_atoi(texte7) != 0) + printf("7: NON\n"); + if(ft_atoi(texte8) != 0) + printf("8: NON\n"); + if(ft_atoi(texte9) != 0) + printf("9: NON\n"); + if(ft_atoi(texte10) != 12) + printf("10: NON\n"); + if(ft_atoi(texte11) != 0) + printf("11: NON\n"); + if(ft_atoi(texte12) != 0) + printf("12: NON\n"); + if(ft_atoi(texte13) != -2147483649L) + printf("13: NON\n"); + if(ft_atoi(texte14) != 2147483649L) + printf("14: NON\n"); + write(1, "\n", 1); + return (0); +}*/ diff --git a/lib/libft/ft_bzero.c b/lib/libft/ft_bzero.c new file mode 100755 index 0000000..a02eb4c --- /dev/null +++ b/lib/libft/ft_bzero.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_bzero.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/07 10:47:55 by yantoine #+# #+# */ +/* Updated: 2023/11/09 15:02:31 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include +#include +#include "libft.h" + +void ft_bzero(void *s, size_t n) +{ + if (n <= 0) + return ; + ft_memset(s, 0, n); +} + +/*int main() +{ + void mess[10] = "oui"; + + ft_bzero() + return (0); +}*/ diff --git a/lib/libft/ft_calloc.c b/lib/libft/ft_calloc.c new file mode 100755 index 0000000..152ee4c --- /dev/null +++ b/lib/libft/ft_calloc.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_calloc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/14 15:24:33 by hexplor #+# #+# */ +/* Updated: 2023/11/30 08:53:17 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_calloc(size_t n, size_t size) +{ + char *tab; + size_t sizemax; + + sizemax = n * size; + if (size && sizemax / size < n) + return (NULL); + if (n == 0 || size == 0) + { + tab = malloc(1); + return (tab); + } + tab = malloc(n * size); + if (!tab) + return (NULL); + ft_bzero(tab, n * size); + return (tab); +} +/*#include +int main() +{ + void *p; + + p = ft_calloc(SIZE_MAX, SIZE_MAX); + free(p); + return (0); +}*/ diff --git a/lib/libft/ft_isalnum.c b/lib/libft/ft_isalnum.c new file mode 100755 index 0000000..cbaa49b --- /dev/null +++ b/lib/libft/ft_isalnum.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalnum.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/07 10:17:01 by yantoine #+# #+# */ +/* Updated: 2023/11/08 08:05:51 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +int ft_isalnum(int c) +{ + if (ft_isalpha(c) == 1 || ft_isdigit(c) == 1) + return (1); + else + return (0); +} diff --git a/lib/libft/ft_isalpha.c b/lib/libft/ft_isalpha.c new file mode 100755 index 0000000..b7095b0 --- /dev/null +++ b/lib/libft/ft_isalpha.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/07 10:02:38 by yantoine #+# #+# */ +/* Updated: 2023/11/08 08:06:13 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +int ft_isalpha(int c) +{ + if ((c >= 65 && c <= 90) \ + || (c >= 97 && c <= 122)) + return (1); + else + return (0); +} diff --git a/lib/libft/ft_isascii.c b/lib/libft/ft_isascii.c new file mode 100755 index 0000000..b9521fa --- /dev/null +++ b/lib/libft/ft_isascii.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isascii.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/07 10:17:41 by yantoine #+# #+# */ +/* Updated: 2023/11/08 08:06:30 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +int ft_isascii(int c) +{ + if (c >= 0 && c <= 127) + return (1); + else + return (0); +} diff --git a/lib/libft/ft_isdigit.c b/lib/libft/ft_isdigit.c new file mode 100755 index 0000000..b78fdd8 --- /dev/null +++ b/lib/libft/ft_isdigit.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isdigit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/07 10:06:07 by yantoine #+# #+# */ +/* Updated: 2023/11/08 08:06:49 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +int ft_isdigit(int c) +{ + if ((c >= 48 && c <= 57)) + return (1); + else + return (0); +} diff --git a/lib/libft/ft_isprint.c b/lib/libft/ft_isprint.c new file mode 100755 index 0000000..9d79e61 --- /dev/null +++ b/lib/libft/ft_isprint.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isprint.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/09 12:37:20 by yantoine #+# #+# */ +/* Updated: 2023/11/30 09:02:47 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +int ft_isprint(int c) +{ + if (c >= 32 && c <= 126) + return (1); + return (0); +} diff --git a/lib/libft/ft_itoa.c b/lib/libft/ft_itoa.c new file mode 100755 index 0000000..e325b44 --- /dev/null +++ b/lib/libft/ft_itoa.c @@ -0,0 +1,104 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_itoa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/22 15:16:11 by hexplor #+# #+# */ +/* Updated: 2023/11/30 07:44:52 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static int ft_n_digit(int n) +{ + long index; + + if (n == 0) + return (1); + index = 0; + while (n != 0) + { + n /= 10; + index++; + } + return (index); +} + +static int ft_pow(int n) +{ + long index; + + index = 1; + while (n != 0) + { + index *= 10; + n--; + } + return (index / 10); +} + +static void ft_set_number(char *tab) +{ + long index; + + index = 0; + while (index != 11) + { + tab[index] = index + '0'; + index++; + } + tab[index] = '\0'; +} + +static void ft_set_digit(long nbr_digit, long index, char *nbr, long n) +{ + char digit[15]; + long pow; + + if (n == 0) + { + *nbr = '0'; + *(nbr + 1) = 0; + return ; + } + ft_set_number(digit); + pow = ft_pow(nbr_digit); + while (nbr_digit != 0) + { + *(nbr + index++) = digit[(n / pow) % 10]; + nbr_digit--; + pow /= 10; + } + *(nbr + index++) = '\0'; +} + +char *ft_itoa(int n) +{ + char *nbr; + long index; + long n2; + long nbr_digit; + + n2 = (long) n; + nbr_digit = ft_n_digit(n); + index = 0; + if (n2 < 0) + { + nbr = ft_calloc((nbr_digit + 2), 1); + if (!nbr) + return (NULL); + *(nbr + index++) = '-'; + n2 *= -1; + } + else + { + nbr = ft_calloc((nbr_digit + 1), 1); + if (!nbr) + return (NULL); + } + ft_set_digit(nbr_digit, index, nbr, n2); + return (nbr); +} diff --git a/lib/libft/ft_memchr.c b/lib/libft/ft_memchr.c new file mode 100755 index 0000000..5e80b6a --- /dev/null +++ b/lib/libft/ft_memchr.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/11 09:03:40 by yantoine #+# #+# */ +/* Updated: 2023/11/13 16:24:52 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memchr(const void *s, int c, size_t n) +{ + unsigned char *p; + size_t index; + + p = (unsigned char *)s; + index = 0; + while (p[index] && index < n) + { + if (*(p + index) == (unsigned char) c) + return ((void *)(p + index)); + index++; + } + return (NULL); +} diff --git a/lib/libft/ft_memcmp.c b/lib/libft/ft_memcmp.c new file mode 100755 index 0000000..16a42a6 --- /dev/null +++ b/lib/libft/ft_memcmp.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/11 10:08:42 by yantoine #+# #+# */ +/* Updated: 2023/11/13 16:23:41 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_memcmp(const void *s1, const void *s2, size_t n) +{ + unsigned char *p1; + unsigned char *p2; + size_t index; + + index = 0; + p1 = (unsigned char *)s1; + p2 = (unsigned char *)s2; + while (index < n) + { + if (*(p1 + index) != *(p2 + index)) + return ((*(p1 + index) - *(p2 + index))); + index++; + } + return (0); +} + +/*int main() +{ + ft_memcmp("001270", "coucou", 7); + return (0); +}*/ diff --git a/lib/libft/ft_memcpy.c b/lib/libft/ft_memcpy.c new file mode 100755 index 0000000..030e42e --- /dev/null +++ b/lib/libft/ft_memcpy.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/07 11:03:13 by yantoine #+# #+# */ +/* Updated: 2023/11/09 12:15:15 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memcpy(void *dest, const void *src, size_t n) +{ + size_t index; + + index = 0; + while (index < n) + { + *(unsigned char *)(dest + index) = *(unsigned char *)(src + index); + index++; + } + return (dest); +} diff --git a/lib/libft/ft_memmove.c b/lib/libft/ft_memmove.c new file mode 100755 index 0000000..1e79e41 --- /dev/null +++ b/lib/libft/ft_memmove.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memmove.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/08 15:13:56 by hexplor #+# #+# */ +/* Updated: 2023/11/09 12:45:23 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memmove(void *dest, const void *src, size_t n) +{ + size_t index; + int index2; + + if (dest > src) + { + index2 = n - 1; + while (index2 >= 0) + { + *(unsigned char *)(dest + index2) = \ + *(unsigned char *)(src + index2); + index2--; + } + } + else + { + index = 0; + while (index < n) + { + *(unsigned char *)(dest + index) = *(unsigned char *)(src + index); + index++; + } + } + return (dest); +} diff --git a/lib/libft/ft_memset.c b/lib/libft/ft_memset.c new file mode 100755 index 0000000..ee95790 --- /dev/null +++ b/lib/libft/ft_memset.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/06 11:33:18 by yantoine #+# #+# */ +/* Updated: 2023/11/09 14:55:20 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include +#include +#include "libft.h" + +void *ft_memset(void *s, int c, size_t n) +{ + size_t index; + + index = 0; + while (index < n) + { + *(unsigned char *)(s + index) = c; + index++; + } + return (s); +} diff --git a/lib/libft/ft_putchar_fd.c b/lib/libft/ft_putchar_fd.c new file mode 100755 index 0000000..9666580 --- /dev/null +++ b/lib/libft/ft_putchar_fd.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/23 14:08:31 by hexplor #+# #+# */ +/* Updated: 2023/11/23 15:04:00 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putchar_fd(char c, int fd) +{ + write(fd, &c, 1); +} diff --git a/lib/libft/ft_putendl_fd.c b/lib/libft/ft_putendl_fd.c new file mode 100755 index 0000000..4797c84 --- /dev/null +++ b/lib/libft/ft_putendl_fd.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putendl_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/23 14:34:12 by hexplor #+# #+# */ +/* Updated: 2023/11/24 17:45:40 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putendl_fd(char *s, int fd) +{ + ft_putstr_fd(s, fd); + ft_putchar_fd('\n', fd); +} diff --git a/lib/libft/ft_putnbr_fd.c b/lib/libft/ft_putnbr_fd.c new file mode 100755 index 0000000..6e3cf3e --- /dev/null +++ b/lib/libft/ft_putnbr_fd.c @@ -0,0 +1,87 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/23 14:41:48 by hexplor #+# #+# */ +/* Updated: 2023/11/27 22:27:06 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static int ft_n_digit(int n) +{ + long index; + + index = 0; + while (n != 0) + { + n /= 10; + index++; + } + return (index); +} + +static int ft_pow(int n) +{ + long index; + + index = 1; + while (n != 0) + { + index *= 10; + n--; + } + return (index / 10); +} + +static void ft_set_number(char *tab) +{ + long index; + + index = 0; + while (index != 11) + { + tab[index] = index + '0'; + index++; + } + tab[index] = '\0'; +} + +static void ft_set_digit(long nbr_digit, long n, int fd) +{ + char digit[15]; + long pow; + + if (n == 0) + { + ft_putchar_fd('0', fd); + return ; + } + ft_set_number(digit); + pow = ft_pow(nbr_digit); + while (nbr_digit != 0) + { + ft_putchar_fd(digit[(n / pow) % 10], fd); + nbr_digit--; + pow /= 10; + } +} + +void ft_putnbr_fd(int n, int fd) +{ + long n2; + long nbr_digit; + + n2 = (long) n; + nbr_digit = ft_n_digit(n); + if (n2 < 0) + { + ft_putchar_fd('-', fd); + n2 *= -1; + } + ft_set_digit(nbr_digit, n2, fd); +} diff --git a/lib/libft/ft_putstr_fd.c b/lib/libft/ft_putstr_fd.c new file mode 100755 index 0000000..e6cf7d7 --- /dev/null +++ b/lib/libft/ft_putstr_fd.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/23 14:24:20 by hexplor #+# #+# */ +/* Updated: 2023/11/23 14:32:00 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putstr_fd(char *s, int fd) +{ + unsigned int i; + + i = 0; + while (*(s + i)) + { + ft_putchar_fd(*(s + i), fd); + i++; + } +} diff --git a/lib/libft/ft_split.c b/lib/libft/ft_split.c new file mode 100755 index 0000000..7ea16c3 --- /dev/null +++ b/lib/libft/ft_split.c @@ -0,0 +1,108 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/16 17:06:15 by hexplor #+# #+# */ +/* Updated: 2023/11/29 13:19:56 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static size_t count_word(char *str, char c) +{ + int count; + + count = 0; + while (*str) + { + while (*str == c) + str++; + if (*str != c && *str) + count++; + while (*str && *str != c) + str++; + } + return (count); +} + +static size_t len_word(char *s, char c, size_t start) +{ + size_t i; + + i = 0; + while (s[start] && s[start] != c) + { + i++; + start++; + } + return (i); +} + +static void free_array(char **s1) +{ + size_t i; + + i = 0; + while (s1[i]) + { + free(s1[i]); + i++; + } + free(s1); +} + +static char **divisor(char *str1, char c, char **array, size_t len) +{ + size_t i; + size_t j; + + i = 0; + j = 0; + while (i < len) + { + while (str1[j] && str1[j] == c) + j++; + array[i] = ft_substr(str1, j, len_word(str1, c, j)); + if (!array[i]) + { + free_array(array); + return (NULL); + } + while (str1[j] && str1[j] != c) + j++; + i++; + } + array[i] = NULL; + return (array); +} + +char **ft_split(char const *s, char c) +{ + size_t words; + char **array; + + if (!s) + return (NULL); + words = count_word((char *)s, c); + array = (char **)malloc((words + 1) * (sizeof(char *))); + if (!array) + return (NULL); + array = divisor((char *)s, c, array, words); + return (array); +} +/* +int main() +{ + char **list; + + list = ft_split("--1-2--3---4----5-----42", '-'); + for (int i = 0; list[i] != NULL; ++i) + free(list[i]); + free(list); + return (0); +} +*/ diff --git a/lib/libft/ft_strchr.c b/lib/libft/ft_strchr.c new file mode 100755 index 0000000..f16e965 --- /dev/null +++ b/lib/libft/ft_strchr.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/10 12:07:02 by hexplor #+# #+# */ +/* Updated: 2023/11/29 15:22:10 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strchr(const char *s, int c) +{ + char *chaine; + + chaine = (char *)s; + while (*chaine) + { + if (*chaine == (unsigned char)c) + return (chaine); + chaine++; + } + if (c == '\0') + return (chaine); + return (NULL); +} diff --git a/lib/libft/ft_strdup.c b/lib/libft/ft_strdup.c new file mode 100755 index 0000000..562f9a7 --- /dev/null +++ b/lib/libft/ft_strdup.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/15 15:58:53 by hexplor #+# #+# */ +/* Updated: 2023/11/29 14:52:09 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strdup(const char *s1) +{ + char *s2; + int index; + + s2 = (char *)ft_calloc(ft_strlen(s1) + 1, 1); + if (s2 == NULL) + return (NULL); + index = 0; + while (*(s1 + index)) + { + *(s2 + index) = *(s1 + index); + index++; + } + *(s2 + index) = '\0'; + return (s2); +} + +/*int main() +{ + char *dest; + + dest = ft_strdup("BONJOUR"); + dest = ft_strdup(""); + dest = ft_strdup("\0"); + return (0); +}*/ diff --git a/lib/libft/ft_striteri.c b/lib/libft/ft_striteri.c new file mode 100755 index 0000000..68de181 --- /dev/null +++ b/lib/libft/ft_striteri.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_striteri.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/23 12:50:39 by hexplor #+# #+# */ +/* Updated: 2023/11/23 13:54:15 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_striteri(char *s, void (*f)(unsigned int, char *)) +{ + unsigned int i; + + i = 0; + while (*s) + { + f(i, s); + i++; + s++; + } +} diff --git a/lib/libft/ft_strjoin.c b/lib/libft/ft_strjoin.c new file mode 100755 index 0000000..06d5c68 --- /dev/null +++ b/lib/libft/ft_strjoin.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/16 12:21:11 by hexplor #+# #+# */ +/* Updated: 2023/11/30 08:49:26 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strjoin(char const *s1, char const *s2) +{ + size_t len; + char *str; + + len = ft_strlen(s1); + len += ft_strlen(s2); + str = (char *)ft_calloc((len + 1), 1); + if (!str) + return (NULL); + ft_memmove(str, s1, ft_strlen(s1)); + ft_memmove((str + ft_strlen(s1)), s2, ft_strlen(s2)); + return (str); +} diff --git a/lib/libft/ft_strlcat.c b/lib/libft/ft_strlcat.c new file mode 100755 index 0000000..1e4b455 --- /dev/null +++ b/lib/libft/ft_strlcat.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/09 09:02:08 by hexplor #+# #+# */ +/* Updated: 2023/11/10 09:54:44 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +size_t ft_strlcat(char *dest, const char *src, size_t size) +{ + size_t i; + size_t k; + + i = 0; + k = 0; + while (dest[i] && i < size) + i++; + while (src[k] && (i + k + 1) < size) + { + dest[i + k] = src[k]; + k++; + } + if (i < size) + dest[i + k] = '\0'; + return (i + ft_strlen(src)); +} + +/*int main() +{ + char mess1[10] = "oui"; + char mess2[10] = "non"; + + ft_strlcat(mess1, mess2, 3); + return (0); +}*/ diff --git a/lib/libft/ft_strlcpy.c b/lib/libft/ft_strlcpy.c new file mode 100755 index 0000000..4cedd6b --- /dev/null +++ b/lib/libft/ft_strlcpy.c @@ -0,0 +1,43 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/09 17:27:30 by hexplor #+# #+# */ +/* Updated: 2023/11/09 20:22:10 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlcpy(char *dest, const char *src, size_t size) +{ + size_t c; + size_t i; + + c = 0; + while (src[c] != '\0') + c++; + i = 0; + if (size != 0) + { + while (src[i] != '\0' && i < (size - 1)) + { + dest[i] = src[i]; + i++; + } + dest[i] = '\0'; + } + return (c); +} + +/*int main() +{ + char dest[10] = "oui"; + char src[3] = "non"; + + ft_strlcpy(dest, src, 10); + return (0); +}*/ diff --git a/lib/libft/ft_strlen.c b/lib/libft/ft_strlen.c new file mode 100755 index 0000000..7ed76b2 --- /dev/null +++ b/lib/libft/ft_strlen.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/07 10:18:42 by yantoine #+# #+# */ +/* Updated: 2023/11/09 12:31:17 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +size_t ft_strlen(const char *c) +{ + int index; + + index = 0; + while (c[index] != 0) + index += 1; + return (index); +} diff --git a/lib/libft/ft_strmapi.c b/lib/libft/ft_strmapi.c new file mode 100755 index 0000000..83db4d1 --- /dev/null +++ b/lib/libft/ft_strmapi.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strmapi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/23 11:52:03 by hexplor #+# #+# */ +/* Updated: 2023/11/30 09:04:01 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) +{ + unsigned int i; + char *str; + + i = 0; + str = ft_calloc((ft_strlen(s) + 1), 1); + if (!str) + return (0); + while (*(s + i)) + { + *(str + i) = f(i, *(s + i)); + i++; + } + *(str + i) = '\0'; + return (str); +} diff --git a/lib/libft/ft_strncmp.c b/lib/libft/ft_strncmp.c new file mode 100755 index 0000000..4c48c8e --- /dev/null +++ b/lib/libft/ft_strncmp.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/11 08:46:16 by yantoine #+# #+# */ +/* Updated: 2023/11/30 09:28:36 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_strncmp(const char *s1, const char *s2, size_t n) +{ + size_t index; + + index = 0; + while (*(unsigned char *)(s1 + index) && \ + *(unsigned char *)(s2 + index) && index < n) + { + if (*(s1 + index) != *(s2 + index)) + return (*(s1 + index) - *(s2 + index)); + index++; + } + return (0); +} diff --git a/lib/libft/ft_strnstr.c b/lib/libft/ft_strnstr.c new file mode 100755 index 0000000..dc17b15 --- /dev/null +++ b/lib/libft/ft_strnstr.c @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/12 12:16:17 by yantoine #+# #+# */ +/* Updated: 2023/11/27 22:29:37 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +char *ft_strnstr(const char *big, const char *little, size_t len) +{ + size_t i; + size_t j; + char *b; + + b = (char *) big; + i = 0; + if (little[i] == '\0' || little == NULL) + return (b); + if (len == 0) + return (0); + while (b[i] != '\0' && i < len) + { + j = 0; + while (little[j] && (i + j) < len) + { + if (b[i + j] == little[j]) + j++; + else + break ; + } + if (little[j] == 0) + return (&b[i]); + i++; + } + return (0); +} +/*int main() +{ + ft_strnstr("aaabcabcd", "abcd", -1); + return (0); +}*/ diff --git a/lib/libft/ft_strrchr.c b/lib/libft/ft_strrchr.c new file mode 100755 index 0000000..dfc1be3 --- /dev/null +++ b/lib/libft/ft_strrchr.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strrchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/11 08:02:01 by yantoine #+# #+# */ +/* Updated: 2023/11/29 14:34:30 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +char *ft_strrchr(const char *s, int c) +{ + int len; + + len = 0; + while (*s) + { + len++; + s++; + } + if (c == '\0' && *s == '\0') + return ((char *)s); + while (len >= 0) + { + if (*s == (unsigned char)c) + return ((char *)s); + s--; + len--; + } + return (NULL); +} diff --git a/lib/libft/ft_strtrim.c b/lib/libft/ft_strtrim.c new file mode 100755 index 0000000..d23003e --- /dev/null +++ b/lib/libft/ft_strtrim.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strtrim.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/16 13:48:16 by hexplor #+# #+# */ +/* Updated: 2023/11/29 13:09:29 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strtrim(char const *s1, char const *set) +{ + int i; + int j; + + i = 0; + j = ft_strlen(s1) - 1; + while (s1[i] && ft_strchr(set, s1[i])) + i++; + while (s1[j] && ft_strchr(set, s1[j])) + j--; + return (ft_substr(s1, i, (j - i + 1))); +} diff --git a/lib/libft/ft_substr.c b/lib/libft/ft_substr.c new file mode 100755 index 0000000..89ada2c --- /dev/null +++ b/lib/libft/ft_substr.c @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_substr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/15 20:04:44 by hexplor #+# #+# */ +/* Updated: 2023/11/30 08:45:42 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_substr(char const *s, unsigned int start, size_t len) +{ + char *str; + size_t i; + + if (!s) + return (NULL); + i = 0; + if (len > ft_strlen(s) - start) + { + len = ft_strlen(s) - start; + } + if (start >= ft_strlen(s)) + return (ft_strdup("")); + str = (char *)malloc(((sizeof(char) * (len + 1)))); + if (!str) + return (NULL); + while (i < len && s[start] != '\0') + { + str[i++] = s[start++]; + } + str[i] = '\0'; + return (str); +} +/* +int main() +{ + char *text; + + text = ft_substr("tripouille", 100, 1); + free(text); + return (0); +}*/ diff --git a/lib/libft/ft_tolower.c b/lib/libft/ft_tolower.c new file mode 100755 index 0000000..604ca24 --- /dev/null +++ b/lib/libft/ft_tolower.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_tolower.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/10 10:09:46 by hexplor #+# #+# */ +/* Updated: 2023/11/10 10:13:40 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_tolower(int c) +{ + if (c >= 97 - 32 && c <= 122 - 32) + return (c + 32); + return (c); +} diff --git a/lib/libft/ft_toupper.c b/lib/libft/ft_toupper.c new file mode 100755 index 0000000..1f09844 --- /dev/null +++ b/lib/libft/ft_toupper.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_toupper.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: hexplor +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/10 10:05:42 by hexplor #+# #+# */ +/* Updated: 2023/11/10 10:09:20 by hexplor ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_toupper(int c) +{ + if (c >= 97 && c <= 122) + return (c - 32); + return (c); +} diff --git a/lib/libft/libft.h b/lib/libft/libft.h new file mode 100755 index 0000000..763c396 --- /dev/null +++ b/lib/libft/libft.h @@ -0,0 +1,88 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/07 09:46:33 by yantoine #+# #+# */ +/* Updated: 2024/04/29 11:09:29 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_H +# define LIBFT_H + +# include +# include +# include +# include + +void *ft_calloc(size_t count, size_t size); + +void ft_putnbr_fd(int n, int fd); + +void ft_putendl_fd(char *s, int fd); + +void ft_striteri(char *s, void (*f)(unsigned int, char*)); + +void *ft_memchr(const void *s, int c, size_t n); + +void *ft_memmove(void *dest, const void *src, size_t n); + +void ft_putchar_fd(char c, int fd); + +void ft_putstr_fd(char *s, int fd); + +void *ft_memset(void *s, int c, size_t n); + +void ft_bzero(void *s, size_t n); + +void *ft_memcpy(void *dest, const void *src, size_t n); + +size_t ft_strlcat(char *dest, const char *src, size_t size); + +size_t ft_strlcpy(char *dest, const char *src, size_t size); + +size_t ft_strlen(const char *c); + +char **ft_split(char const *s, char c); + +char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); + +char *ft_itoa(int n); + +char *ft_strtrim(char const *s1, char const *set); + +char *ft_strjoin(char const *s1, char const *s2); + +char *ft_substr(char const *s, unsigned int start, size_t len); + +char *ft_strdup(const char *s1); + +char *ft_strchr(const char *s, int c); + +char *ft_strrchr(const char *s, int c); + +char *ft_strnstr(const char *big, const char *little, size_t len); + +int ft_memcmp(const void *s1, const void *s2, size_t n); + +int ft_strncmp(const char *s1, const char *s2, size_t n); + +int ft_toupper(int c); + +int ft_tolower(int c); + +int ft_isprint(int c); + +int ft_isalpha(int c); + +int ft_isdigit(int c); + +int ft_isalnum(int c); + +int ft_isascii(int c); + +long ft_atoi(const char *str); +#endif diff --git a/src/.find_last.c.swp b/src/.find_last.c.swp new file mode 100644 index 0000000000000000000000000000000000000000..5fe7810cbfc34fedbe48e18d909441f76c54e3a0 GIT binary patch literal 12288 zcmeI2&2AD=6vt295k-w|8r|H&LJDC9rnI%A5=2cjX%k~omy%)T5+)2YlbNA~812d@ z@Ij1m>kH@uxYnf`cQ)?yT)3AH(;9+oNX{XD?ztc5KllEC1(|7)4OGEu(VE4M* zPh!1dG-A6Q1fCxD;&vlGwn9CQY`x|BPQ$a}M6;(IC?^6$U~vLz*fPo`QJ>9huglLjrw>Qpo6-B`jiIfqi&(TTmpE5 zYN9Mu9aTf=C=IoaN~2EE`zz`*>H}(ctrcWNTP6ZTfCvx)B0vO)01+Sp=MoS%(1d37S=rm=ITAdMKTto>Dh3{^I;k6)6inqb<*AN5SvzMY z+$N5=PwB1<$KO27p3{+;1#`4iCZk3f&g(L>&NP)JW+HI*zYJ&GWoKl#v>yuo=ydo4 Dc!?~G literal 0 HcmV?d00001 diff --git a/src/.find_max.c.swp b/src/.find_max.c.swp new file mode 100644 index 0000000000000000000000000000000000000000..01d36b7e4f8f41d2bc854d36113bc070028286cf GIT binary patch literal 12288 zcmeI2Pixdb9EN}GE$XW1&4WxE!FHET_TQmRb+N62LJK0)qf0iKvT3tPNV4sgq6NV( z;K>i*S-*gH(GQ^D&9ms)qi;5u?y5zK?WORW<;_gy&$Bbnb`NFKtv!CQE*6bCp$zO_a_z7qB1F!IAV8~JBhx1E(R+^#Nran+U8`*Qfu4<8wR=-B?`!e<50yc;@$ zz6{dDY&ANG(+fl2j0Q=slkD1&nZ%B{=>=}5Zx0P;62NUXzy?lWphV3^y_Ny=*%@*5 z%Ek#;yp#>F0XDz}*Z><~18jf|uz|B?AdRNz0GpmJHh#URr~asmTdvpu8(;%$fDNz# zHoykh02^QfY=8~0fiq~pc8R{6BicHT&Exlf_5c6dOGHnQ67udM(Kd1o`A{MnA~%sw z7l>XUUBpIKk!7TY+(2}sgiIsf!2gVVMBXEBkXOia0fE$r(r_!}Vqt?HqV&Ule@lO!@_$XD1i{ literal 0 HcmV?d00001 diff --git a/src/.find_min.c.swp b/src/.find_min.c.swp new file mode 100644 index 0000000000000000000000000000000000000000..2b3b36fd65dfcb4eaaaa43bfdb9230c971cd0184 GIT binary patch literal 12288 zcmeI2Uu)A)9EN|}UDT@RouHg8f?G?I{+XcJ9BxyX;6Q|VX-Sh)8kZ&^Nw=1v1Htd$ zr_e9pz32x}@Xl*N^nMq!)8Lx$VU;CITKb8`MXJ?H6qF`9Pm$%74X+o%)DMWUZ1|yL`;!Y_6hQM{==6Is zNE36R(Mp_d82V<^Pr9vS$BxV-cFc|!xUHTS7|tYs+iZXh9K%3~nvHrb1L(6e;_{`< zW3YHB8(;%$fDNz#Hoykh02^Qfr_DebP0=1UJzZ@4T2W8^Q5Uydu>m%~2G{@_U;}J` z4X^<=zy{a=8(;&c(17g{eK|w)>?}5q-~ZMB|8Fl4Jw-~$yYoa_$Q9&6iD-b_Kt7!# zdWEzR8(BkEkQ#Cw(UB4|jeG{;|&WQp_5LS+tY!ZMx2fUl4_&|fySZLr-%j0z; zNX1g538p&oc<2(aH)2j|H5B Pt9A}Nu`dd~bSC`*OzJ1y literal 0 HcmV?d00001 diff --git a/src/assign_param_list.c b/src/assign_param_list.c new file mode 100644 index 0000000..b723448 --- /dev/null +++ b/src/assign_param_list.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* assign_param_list.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/13 19:51:13 by yantoine #+# #+# */ +/* Updated: 2024/03/20 13:26:37 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../includes/push_swap.h" + +void assign_param_list(t_Liste *liste) +{ + if (!liste->premier) + return ; + list_lenght(liste); + list_index(liste); + find_min(liste); + find_max(liste); + find_last(liste); + find_moyenne(liste); + set_precedant(liste); +} diff --git a/src/big_sort.c b/src/big_sort.c new file mode 100644 index 0000000..64877ac --- /dev/null +++ b/src/big_sort.c @@ -0,0 +1,91 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* big_sort.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/15 21:04:05 by yantoine #+# #+# */ +/* Updated: 2024/03/21 18:11:09 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +/* +#include "../includes/push_swap.h" + +static int wich_algo(t_Liste *stack_a, t_Liste *stack_b) +{ + if (stack_a->premier->number > stack_b->max) + return (1); + else if (stack_a->premier->number < stack_b->min) + return (2); + else + return (3); +} + +static void exec_algo(t_Liste *stack_a, t_Liste *stack_b, int algo) +{ + int i; + + i = 0; + if (algo == 1) + push(stack_a, stack_b, 'b'); + else if (algo == 2) + { + push(stack_a, stack_b, 'b'); + rotate(stack_b, 'b'); + } + else + { + if (stack_a->premier->number >= stack_b->moyenne) + { + while (stack_a->premier->number < stack_b->premier->number) + { + rotate(stack_b, 'b'); + i++; + } + while (stack_a->premier->number >= stack_b->premier->number \ + && stack_a->premier->number <= stack_b->dernier->number) + push(stack_a, stack_b, 'b'); + while (i > 0) + { + if (stack_a->premier->number > stack_b->premier->number \ + && stack_a->premier->number < stack_b->dernier->number) + push(stack_a, stack_b, 'b'); + reverse_rotate(stack_b, 'b'); + i--; + } + } + else + { + while (stack_a->premier->number < stack_b->premier->number \ + || stack_a->premier->number > stack_b->dernier->number) + { + reverse_rotate(stack_b, 'b'); + i++; + } + while (stack_a->premier->number >= stack_b->premier->number \ + && stack_a->premier->number <= stack_b->dernier->number) + push(stack_a, stack_b, 'b'); + while (i >= 0) + { + if (stack_a->premier->number < stack_b->premier->number \ + && stack_a->premier->number > stack_b->dernier->number) + push(stack_a, stack_b, 'b'); + rotate(stack_b, 'b'); + i--; + } + } + } +} + +void big_sort(t_Liste *stack_a, t_Liste *stack_b) +{ + int size; + + size = stack_a->length; + while (stack_a->length > 1) + exec_algo(stack_a, stack_b, wich_algo(stack_a, stack_b)); + while (stack_a->length != size) + push(stack_a, stack_b, 'a'); +} +*/ diff --git a/src/condition.c b/src/condition.c new file mode 100644 index 0000000..32217d5 --- /dev/null +++ b/src/condition.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* condition.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/21 18:03:40 by yantoine #+# #+# */ +/* Updated: 2024/03/21 23:43:04 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../includes/push_swap.h" + +int condition(t_Element *actuel_a, t_Element *actuel_b, t_Liste *stack_b) +{ + if (actuel_a->number < stack_b->min) + { + if (actuel_b->number == stack_b->max) + { + return (1); + } + } + else if (actuel_a->number > stack_b->max) + { + if (actuel_b->number == stack_b->max) + { + return (1); + } + } + else if (actuel_a->number > actuel_b->number \ + && actuel_a->number < actuel_b->precedant_boucle->number) + { + return (1); + } + return (0); +} diff --git a/src/find_last.c b/src/find_last.c new file mode 100644 index 0000000..8a52292 --- /dev/null +++ b/src/find_last.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* find_last.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/18 20:15:26 by yantoine #+# #+# */ +/* Updated: 2024/03/18 20:16:57 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../includes/push_swap.h" + +void find_last(t_Liste *liste) +{ + t_Element *tmp; + + if (!liste->premier) + return ; + tmp = liste->premier; + while (tmp->suivant) + tmp = tmp->suivant; + liste->dernier = tmp; +} diff --git a/src/find_lower_rank.c b/src/find_lower_rank.c new file mode 100644 index 0000000..ff869a9 --- /dev/null +++ b/src/find_lower_rank.c @@ -0,0 +1,51 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* find_lower_rank.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/21 18:07:46 by yantoine #+# #+# */ +/* Updated: 2024/03/21 23:43:16 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../includes/push_swap.h" + +static int lower_instruction(t_Element *element) +{ + int lower; + + lower = 0; + lower = element->instruction; + element->wich_instr = 0; + if (lower > element->instruction_ra) + { + lower = element->instruction_ra; + element->wich_instr = 1; + } + if (lower > element->instruction_rb) + { + lower = element->instruction_rb; + element->wich_instr = 2; + } + if (lower > element->instruction_rab) + { + lower = element->instruction_rab; + element->wich_instr = 3; + } + return (lower); +} + +void find_lower_rank(t_Liste *stack) +{ + t_Element *actuel; + + actuel = stack->premier; + stack->lower_rank = actuel; + while (actuel) + { + if (lower_instruction(actuel) < lower_instruction(stack->lower_rank)) + stack->lower_rank = actuel; + actuel = actuel->suivant; + } +} diff --git a/src/find_max.c b/src/find_max.c new file mode 100644 index 0000000..2c57312 --- /dev/null +++ b/src/find_max.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* find_max.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/18 20:13:28 by yantoine #+# #+# */ +/* Updated: 2024/03/18 20:14:44 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../includes/push_swap.h" + +void find_max(t_Liste *liste) +{ + t_Element *tmp; + int max; + + if (!liste->premier) + return ; + tmp = liste->premier; + max = tmp->number; + while (tmp) + { + if (tmp->number > max) + max = tmp->number; + tmp = tmp->suivant; + } + liste->max = max; +} diff --git a/src/find_min.c b/src/find_min.c new file mode 100644 index 0000000..1efa3c1 --- /dev/null +++ b/src/find_min.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* find_min.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/13 18:10:13 by yantoine #+# #+# */ +/* Updated: 2024/03/13 20:18:53 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../includes/push_swap.h" + +void find_min(t_Liste *liste) +{ + t_Element *tmp; + int min; + + if (!liste->premier) + return ; + tmp = liste->premier; + min = tmp->number; + while (tmp) + { + if (tmp->number < min) + min = tmp->number; + tmp = tmp->suivant; + } + liste->min = min; +} diff --git a/src/find_moyenne.c b/src/find_moyenne.c new file mode 100644 index 0000000..b793ca7 --- /dev/null +++ b/src/find_moyenne.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* find_moyenne.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/18 01:14:19 by yantoine #+# #+# */ +/* Updated: 2024/03/18 01:47:52 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../includes/push_swap.h" + +void find_moyenne(t_Liste *liste) +{ + t_Element *actuel; + int moyenne; + int nbr; + + moyenne = 0; + nbr = 0; + actuel = liste->premier; + while (actuel) + { + moyenne += actuel->number; + actuel = actuel->suivant; + nbr++; + } + liste->moyenne = moyenne / nbr; +} diff --git a/src/find_quicker.c b/src/find_quicker.c new file mode 100644 index 0000000..32a9eac --- /dev/null +++ b/src/find_quicker.c @@ -0,0 +1,134 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* find_quicker.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/19 12:31:16 by yantoine #+# #+# */ +/* Updated: 2024/04/29 11:10:44 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../includes/push_swap.h" +//faire pour moyenne haute et moyenne basse + +static void boucle(t_Liste *stack_a, t_Liste *stack_b) +{ + int i; + int j; + t_Element *actuel_a; + t_Element *actuel_b; + + i = 0; + actuel_a = stack_a->premier; + while (actuel_a) + { + j = 0; + actuel_b = stack_b->premier; + while (actuel_b) + { + if (condition(actuel_a, actuel_b, stack_b)) + { + actuel_a->instruction = j + i ; + actuel_a->ptr_num = actuel_b->number; + } + actuel_b = actuel_b->suivant; + j++; + } + actuel_a = actuel_a->suivant; + i++; + } +} + +static void boucle_inverse_a(t_Liste *stack_a, t_Liste *stack_b) +{ + int i; + int j; + t_Element *actuel_a; + t_Element *actuel_b; + + i = 0; + actuel_a = stack_a->dernier; + while (actuel_a) + { + j = 0; + actuel_b = stack_b->premier; + while (actuel_b) + { + if (condition(actuel_a, actuel_b, stack_b)) + { + actuel_a->instruction_ra = j + i; + actuel_a->ptr_num = actuel_b->number; + } + actuel_b = actuel_b->suivant; + j++; + } + actuel_a = actuel_a->precedant; + i++; + } +} + +static void boucle_inverse_b(t_Liste *stack_a, t_Liste *stack_b) +{ + int i; + int j; + t_Element *actuel_a; + t_Element *actuel_b; + + i = 0; + actuel_a = stack_a->premier; + while (actuel_a) + { + j = 0; + actuel_b = stack_b->dernier; + while (actuel_b) + { + if (condition(actuel_a, actuel_b, stack_b)) + { + actuel_a->instruction_rb = j + i; + actuel_a->ptr_num = actuel_b->number; + } + actuel_b = actuel_b->precedant; + j++; + } + actuel_a = actuel_a->suivant; + i++; + } +} + +static void boucle_inverse_ab(t_Liste *stack_a, t_Liste *stack_b) +{ + int i; + int j; + t_Element *actuel_a; + t_Element *actuel_b; + + i = 0; + actuel_a = stack_a->dernier; + while (actuel_a) + { + j = 0; + actuel_b = stack_b->dernier; + while (actuel_b) + { + if (condition(actuel_a, actuel_b, stack_b)) + { + actuel_a->instruction_rab = j + i; + actuel_a->ptr_num = actuel_b->number; + } + actuel_b = actuel_b->precedant; + j++; + } + actuel_a = actuel_a->precedant; + i++; + } +} + +void find_quicker(t_Liste *stack_a, t_Liste *stack_b) +{ + boucle(stack_a, stack_b); + boucle_inverse_a(stack_a, stack_b); + boucle_inverse_b(stack_a, stack_b); + boucle_inverse_ab(stack_a, stack_b); + find_lower_rank(stack_a); +} diff --git a/src/free_stack.c b/src/free_stack.c new file mode 100644 index 0000000..ae8afc8 --- /dev/null +++ b/src/free_stack.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* free_stack.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/13 18:26:53 by yantoine #+# #+# */ +/* Updated: 2024/03/14 22:58:30 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../includes/push_swap.h" + +void free_stack(t_Liste *stack_a, t_Liste *stack_b) +{ + t_Element *tmp; + + if (stack_a) + { + while (stack_a->premier) + { + tmp = stack_a->premier; + stack_a->premier = stack_a->premier->suivant; + free(tmp); + } + } + if (stack_b) + { + while (stack_b->premier) + { + tmp = stack_b->premier; + stack_b->premier = stack_b->premier->suivant; + free(tmp); + } + } + if (stack_a) + free(stack_a); + if (stack_b) + free(stack_b); +} diff --git a/src/ft_list_find.c b/src/ft_list_find.c new file mode 100644 index 0000000..31db9f6 --- /dev/null +++ b/src/ft_list_find.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list_find.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/13 00:28:07 by yantoine #+# #+# */ +/* Updated: 2024/03/13 00:30:59 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../includes/push_swap.h" + +t_Element *ft_list_find(t_Liste *liste, int nb) +{ + t_Element *element; + + if (!liste) + return (NULL); + element = liste->premier; + while (element) + { + if (element->number == nb) + return (element); + element = element->suivant; + } + return (NULL); +} diff --git a/src/ft_list_push_back.c b/src/ft_list_push_back.c new file mode 100644 index 0000000..7d35387 --- /dev/null +++ b/src/ft_list_push_back.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list_push_back.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/13 16:46:06 by yantoine #+# #+# */ +/* Updated: 2024/03/21 22:49:32 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../includes/push_swap.h" + +void ft_list_push_back(t_Liste *liste, int valeur) +{ + t_Element *element; + t_Element *current; + + element = malloc(sizeof(*element)); + if (!element) + return ; + element->number = valeur; + element->ptr_num = 0; + element->instruction = 0; + element->instruction_ra = 0; + element->instruction_rb = 0; + element->instruction_rab = 0; + element->suivant = NULL; + if (liste->premier == NULL) + liste->premier = element; + else + { + current = liste->premier; + while (current->suivant) + current = current->suivant; + current->suivant = element; + } +} diff --git a/src/is_sorted.c b/src/is_sorted.c new file mode 100644 index 0000000..3b0b88e --- /dev/null +++ b/src/is_sorted.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* is_sorted.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/12 21:19:44 by yantoine #+# #+# */ +/* Updated: 2024/04/26 16:42:18 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../includes/push_swap.h" + +int is_sorted(t_Liste *stack_a) +{ + t_Element *current; + + if (!stack_a) + return (0); + if (stack_a->length == 0) + return (1); + current = stack_a->premier; + while (current->suivant) + { + if (current->number > current->suivant->number) + return (0); + current = current->suivant; + } + return (1); +} diff --git a/src/list_index.c b/src/list_index.c new file mode 100644 index 0000000..cd6e0d4 --- /dev/null +++ b/src/list_index.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* list_index.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/13 20:41:18 by yantoine #+# #+# */ +/* Updated: 2024/03/13 20:41:42 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../includes/push_swap.h" + +void list_index(t_Liste *liste) +{ + t_Element *tmp; + int i; + + i = 0; + tmp = liste->premier; + while (tmp) + { + tmp->index = i; + tmp = tmp->suivant; + i++; + } +} diff --git a/src/list_lenght.c b/src/list_lenght.c new file mode 100644 index 0000000..548c69f --- /dev/null +++ b/src/list_lenght.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* list_lenght.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/12 23:57:34 by yantoine #+# #+# */ +/* Updated: 2024/03/13 20:20:04 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../includes/push_swap.h" + +void list_lenght(t_Liste *liste) +{ + t_Element *current; + int i; + + if (!liste || !liste->premier) + return ; + i = 0; + current = liste->premier; + while (current) + { + current = current->suivant; + i++; + } + liste->length = i; +} diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..c3473e5 --- /dev/null +++ b/src/main.c @@ -0,0 +1,82 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/12 14:15:12 by yantoine #+# #+# */ +/* Updated: 2024/04/26 15:14:46 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../includes/push_swap.h" + +static int manage_arg(t_Liste *stack_a, int argc, char **argv) +{ + if (argc == 2) + { + if (!parse_arg(stack_a, argv[1])) + return (0); + } + else + { + if (!parse_args(stack_a, argc, argv)) + return (0); + } + list_lenght(stack_a); + return (1); +} + +static t_Liste *init_stacks(t_Liste *stack_a) +{ + stack_a = malloc(sizeof(t_Liste)); + if (!stack_a) + { + write(2, "Error\n", 6); + return (NULL); + } + stack_a->premier = NULL; + stack_a->length = 0; + stack_a->moyenne = 0; + stack_a->lower_rank = NULL; + return (stack_a); +} + +static void anti_25_ligne(t_Liste *stack_a, t_Liste *stack_b) +{ + if (!is_sorted(stack_a)) + { + if (stack_a->length == 2) + swap(stack_a, 'a'); + else if (stack_a->length == 3) + sort_3(stack_a); + else if (stack_a->length == 4) + sort_4(stack_a, stack_b); + else if (stack_a->length == 5) + sort_5(stack_a, stack_b); + else + turc(stack_a, stack_b); + } +} + +int main(int argc, char **argv) +{ + t_Liste *stack_a; + t_Liste *stack_b; + + stack_a = NULL; + stack_b = NULL; + stack_a = init_stacks(stack_a); + stack_b = init_stacks(stack_b); + if (argc < 2 || !manage_arg(stack_a, argc, argv)) + { + free_stack(stack_a, stack_b); + if (argc != 1) + write(2, "Error\n", 6); + return (0); + } + assign_param_list(stack_a); + anti_25_ligne(stack_a, stack_b); + free_stack(stack_a, stack_b); + return (0); +} diff --git a/src/normal_trie.c b/src/normal_trie.c new file mode 100644 index 0000000..95965f2 --- /dev/null +++ b/src/normal_trie.c @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* normal_trie.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/21 19:47:09 by yantoine #+# #+# */ +/* Updated: 2024/04/26 16:47:10 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../includes/push_swap.h" + +void normal_trie(t_Liste *stack_a, t_Liste *stack_b) +{ + if (!stack_a || !stack_b) + return ; + while (stack_a->premier != stack_a->lower_rank \ + && stack_b->premier->number != stack_a->lower_rank->ptr_num) + rotate_both(stack_a, stack_b); + while (stack_a->premier != stack_a->lower_rank) + rotate(stack_a, 'a'); + while (stack_b->premier->number != stack_a->lower_rank->ptr_num) + rotate(stack_b, 'b'); + push(stack_a, stack_b, 'b'); +} + +void reverse_a_trie(t_Liste *stack_a, t_Liste *stack_b) +{ + while (stack_a->premier != stack_a->lower_rank) + reverse_rotate(stack_a, 'a'); + while (stack_b->premier->number != stack_a->lower_rank->ptr_num) + rotate(stack_b, 'b'); + push(stack_a, stack_b, 'b'); +} + +void reverse_b_trie(t_Liste *stack_a, t_Liste *stack_b) +{ + while (stack_a->premier != stack_a->lower_rank) + rotate(stack_a, 'a'); + while (stack_b->premier->number != stack_a->lower_rank->ptr_num) + reverse_rotate(stack_b, 'b'); + push(stack_a, stack_b, 'b'); +} + +void reverse_ab_trie(t_Liste *stack_a, t_Liste *stack_b) +{ + while (stack_a->premier != stack_a->lower_rank \ + && stack_b->premier->number != stack_a->lower_rank->ptr_num) + reverse_rotate_both(stack_a, stack_b); + while (stack_a->premier != stack_a->lower_rank) + reverse_rotate(stack_a, 'a'); + while (stack_b->premier->number != stack_a->lower_rank->ptr_num) + reverse_rotate(stack_b, 'b'); + push(stack_a, stack_b, 'b'); +} diff --git a/src/parse_arg.c b/src/parse_arg.c new file mode 100644 index 0000000..242b75f --- /dev/null +++ b/src/parse_arg.c @@ -0,0 +1,82 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parse_arg.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/12 14:31:18 by yantoine #+# #+# */ +/* Updated: 2024/04/29 11:11:48 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../includes/push_swap.h" + +static void ft_free_split(char **split) +{ + int i; + + i = 0; + if (!split) + return ; + while (split[i]) + { + free(split[i]); + i++; + } + free(split); +} + +static int verif_string(char *string) +{ + int i; + + i = 0; + while (string[i]) + { + if (!ft_isdigit(string[i]) && \ + string[i] != '-' && string[i] != '+') + return (0); + i++; + } + return (1); +} + +static int ft_atoi_custom(char *string, t_Liste *stack) +{ + long int nb; + + if (!string || stack == NULL) + return (0); + nb = ft_atoi(string); + if (nb > INT_MAX || nb < INT_MIN) + return (0); + if (ft_list_find(stack, nb)) + return (0); + ft_list_push_back(stack, nb); + return (1); +} + +int parse_arg(t_Liste *stack_a, char *arg) +{ + int i; + char **split; + + i = 0; + split = ft_split(arg, ' '); + while (split[i]) + { + if (!verif_string(split[i])) + { + ft_free_split(split); + return (0); + } + if (!ft_atoi_custom(split[i], stack_a)) + { + ft_free_split(split); + return (0); + } + i++; + } + ft_free_split(split); + return (1); +} diff --git a/src/parse_args.c b/src/parse_args.c new file mode 100644 index 0000000..ad228e5 --- /dev/null +++ b/src/parse_args.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parse_args.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/12 14:36:07 by yantoine #+# #+# */ +/* Updated: 2024/03/14 22:09:01 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../includes/push_swap.h" + +int parse_args(t_Liste *stack_a, int argc, char **argv) +{ + int i; + + i = 1; + while (i < argc) + { + if (!parse_arg(stack_a, argv[i])) + return (0); + i++; + } + return (1); +} diff --git a/src/push.c b/src/push.c new file mode 100644 index 0000000..bbee494 --- /dev/null +++ b/src/push.c @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* push.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/13 18:01:44 by yantoine #+# #+# */ +/* Updated: 2024/04/29 11:12:14 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../includes/push_swap.h" + +static void anti_25(t_Liste *stack_a, t_Liste *stack_b) +{ + assign_param_list(stack_a); + assign_param_list(stack_b); +} + +void push(t_Liste *stack_a, t_Liste *stack_b, char c) +{ + t_Element *tmp; + + if (c == 'a') + { + tmp = stack_b->premier; + if (tmp) + { + stack_b->premier = stack_b->premier->suivant; + tmp->suivant = stack_a->premier; + stack_a->premier = tmp; + } + write(1, "pa\n", 3); + } + else if (c == 'b') + { + tmp = stack_a->premier; + if (tmp) + { + stack_a->premier = stack_a->premier->suivant; + tmp->suivant = stack_b->premier; + stack_b->premier = tmp; + } + write(1, "pb\n", 3); + } + anti_25(stack_a, stack_b); +} diff --git a/src/push_two_number.c b/src/push_two_number.c new file mode 100644 index 0000000..26a3c6b --- /dev/null +++ b/src/push_two_number.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* push_two_number.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/19 12:28:15 by yantoine #+# #+# */ +/* Updated: 2024/03/19 12:34:04 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../includes/push_swap.h" + +void push_two_number(t_Liste *stack_a, t_Liste *stack_b) +{ + push(stack_a, stack_b, 'b'); + push(stack_a, stack_b, 'b'); + if (is_sorted(stack_b)) + swap(stack_b, 'b'); +} diff --git a/src/reverse_rotate.c b/src/reverse_rotate.c new file mode 100644 index 0000000..2242c9d --- /dev/null +++ b/src/reverse_rotate.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* reverse_rotate.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/13 17:43:31 by yantoine #+# #+# */ +/* Updated: 2024/03/13 20:05:48 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../includes/push_swap.h" + +void reverse_rotate(t_Liste *liste, char c) +{ + t_Element *tmp; + t_Element *tmp2; + + if (liste->length < 2) + return ; + tmp = liste->premier; + while (tmp->suivant->suivant) + tmp = tmp->suivant; + tmp2 = tmp->suivant; + tmp->suivant = NULL; + tmp2->suivant = liste->premier; + liste->premier = tmp2; + if (c == 'a') + write(1, "rra\n", 4); + else if (c == 'b') + write(1, "rrb\n", 4); + assign_param_list(liste); +} + +void reverse_rotate_both(t_Liste *stack_a, t_Liste *stack_b) +{ + reverse_rotate(stack_a, 0); + reverse_rotate(stack_b, 0); + write(1, "rrr\n", 4); +} diff --git a/src/rotate.c b/src/rotate.c new file mode 100644 index 0000000..ca94a71 --- /dev/null +++ b/src/rotate.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rotate.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/13 17:16:48 by yantoine #+# #+# */ +/* Updated: 2024/03/13 20:06:58 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../includes/push_swap.h" + +void rotate(t_Liste *liste, char c) +{ + t_Element *tmp; + + if (liste->length < 2) + return ; + tmp = liste->premier; + liste->premier = liste->premier->suivant; + liste->dernier->suivant = tmp; + liste->dernier = tmp; + tmp->suivant = NULL; + if (c == 'a') + write(1, "ra\n", 3); + else if (c == 'b') + write(1, "rb\n", 3); + assign_param_list(liste); +} + +void rotate_both(t_Liste *stack_a, t_Liste *stack_b) +{ + rotate(stack_a, 0); + rotate(stack_b, 0); + write(1, "rr\n", 3); +} diff --git a/src/set_precedant.c b/src/set_precedant.c new file mode 100644 index 0000000..473a01a --- /dev/null +++ b/src/set_precedant.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* set_precedant.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/20 13:22:29 by yantoine #+# #+# */ +/* Updated: 2024/03/21 23:48:37 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../includes/push_swap.h" + +void set_precedant(t_Liste *liste) +{ + t_Element *actuel; + t_Element *precedant; + + actuel = liste->premier; + while (actuel) + { + precedant = actuel; + actuel = actuel->suivant; + if (!actuel) + break ; + actuel->precedant = precedant; + actuel->precedant_boucle = precedant; + if (actuel->suivant == NULL) + break ; + } + liste->premier->precedant = NULL; + liste->premier->precedant_boucle = liste->dernier; +} diff --git a/src/sort_3.c b/src/sort_3.c new file mode 100644 index 0000000..3580e51 --- /dev/null +++ b/src/sort_3.c @@ -0,0 +1,59 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* sort_3.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/13 00:49:31 by yantoine #+# #+# */ +/* Updated: 2024/03/14 23:18:56 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../includes/push_swap.h" + +static void anti_25(t_Liste *stack_a, int min, int max) +{ + if (stack_a->premier->suivant->number == max) + { + if (stack_a->premier->suivant->suivant->number == min) + reverse_rotate(stack_a, 'a'); + else + { + reverse_rotate(stack_a, 'a'); + swap(stack_a, 'a'); + } + } + else + { + if (stack_a->premier->suivant->suivant->number == max) + swap(stack_a, 'a'); + else + { + reverse_rotate(stack_a, 'a'); + swap(stack_a, 'a'); + } + } +} + +void sort_3(t_Liste *stack_a) +{ + int min; + int max; + + if (is_sorted(stack_a)) + return ; + min = stack_a->min; + max = stack_a->max; + if (stack_a->premier->number == max) + { + if (stack_a->premier->suivant->number == min) + rotate(stack_a, 'a'); + else + { + swap(stack_a, 'a'); + reverse_rotate(stack_a, 'a'); + } + } + else + anti_25(stack_a, min, max); +} diff --git a/src/sort_4.c b/src/sort_4.c new file mode 100644 index 0000000..0a9ae0b --- /dev/null +++ b/src/sort_4.c @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* sort_4.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/13 20:34:09 by yantoine #+# #+# */ +/* Updated: 2024/03/14 23:22:34 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../includes/push_swap.h" + +void suite(t_Liste *stack_a, t_Liste *stack_b) +{ + sort_3(stack_a); + push(stack_a, stack_b, 'a'); + if (!is_sorted(stack_a)) + rotate(stack_a, 'a'); +} + +void sort_4(t_Liste *stack_a, t_Liste *stack_b) +{ + int min; + int max; + int i; + + if (is_sorted(stack_a)) + return ; + min = stack_a->min; + max = stack_a->max; + i = 0; + while (i < 4) + { + if (stack_a->premier->number == min \ + || stack_a->premier->number == max) + { + push(stack_a, stack_b, 'b'); + break ; + } + else + rotate(stack_a, 'a'); + i++; + } + suite(stack_a, stack_b); +} diff --git a/src/sort_5.c b/src/sort_5.c new file mode 100644 index 0000000..9d35ee0 --- /dev/null +++ b/src/sort_5.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* sort_5.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/13 16:58:35 by yantoine #+# #+# */ +/* Updated: 2024/03/14 22:57:44 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../includes/push_swap.h" + +void sort_5(t_Liste *stack_a, t_Liste *stack_b) +{ + int min; + int max; + int i; + + if (is_sorted(stack_a)) + return ; + min = stack_a->min; + max = stack_a->max; + i = 0; + while (i < 5) + { + if (stack_a->premier->number == min \ + || stack_a->premier->number == max) + { + push(stack_a, stack_b, 'b'); + break ; + } + else + rotate(stack_a, 'a'); + i++; + } + sort_4(stack_a, stack_b); + push(stack_a, stack_b, 'a'); + if (!is_sorted(stack_a)) + rotate(stack_a, 'a'); +} diff --git a/src/swap.c b/src/swap.c new file mode 100644 index 0000000..a9c1f21 --- /dev/null +++ b/src/swap.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* swap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/13 17:34:45 by yantoine #+# #+# */ +/* Updated: 2024/03/14 22:27:09 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../includes/push_swap.h" + +void swap(t_Liste *liste, char c) +{ + t_Element *tmp; + + if (liste->length < 2) + return ; + tmp = liste->premier; + liste->premier = liste->premier->suivant; + tmp->suivant = liste->premier->suivant; + liste->premier->suivant = tmp; + if (c == 'a') + write(1, "sa\n", 3); + else if (c == 'b') + write(1, "sb\n", 3); + assign_param_list(liste); +} + +void swap_both(t_Liste *stack_a, t_Liste *stack_b) +{ + swap(stack_a, 0); + swap(stack_b, 0); + write(1, "ss\n", 3); +} diff --git a/src/turc.c b/src/turc.c new file mode 100644 index 0000000..4db5376 --- /dev/null +++ b/src/turc.c @@ -0,0 +1,100 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* turc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/19 12:14:47 by yantoine #+# #+# */ +/* Updated: 2024/03/23 23:05:29 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "../includes/push_swap.h" +/* +void print_stacks(t_Liste *stack_a, t_Liste *stack_b) +{ + t_Element *actuel_a; + t_Element *actuel_b; + + actuel_a = stack_a->premier; + actuel_b = stack_b->premier; + printf("\n"); + printf("\n"); + while (actuel_a || actuel_b) + { + if (actuel_a) + { + printf("instruction %d__", actuel_a->instruction); + printf("%d__", actuel_a->instruction_ra); + printf("%d__", actuel_a->instruction_rb); + printf("%d__|", actuel_a->instruction_rab); + printf("%ld ", actuel_a->number); + actuel_a = actuel_a->suivant; + } + else + printf(" "); + if (actuel_b) + { + printf("%ld\n", actuel_b->number); + actuel_b = actuel_b->suivant; + } + else + printf("\n"); + } + printf("\n"); +} +*/ +static void wich_algo(t_Liste *stack_a, t_Liste *stack_b) +{ + if (stack_a->lower_rank->wich_instr == 0) + { + normal_trie(stack_a, stack_b); + } + else if (stack_a->lower_rank->wich_instr == 1) + { + reverse_a_trie(stack_a, stack_b); + } + else if (stack_a->lower_rank->wich_instr == 2) + { + reverse_b_trie(stack_a, stack_b); + } + else + { + reverse_ab_trie(stack_a, stack_b); + } +} + +static void anti_25_ligne(t_Liste *stack_a, t_Liste *stack_b, long length) +{ + while (stack_a->length > 1) + { + find_quicker(stack_a, stack_b); + wich_algo(stack_a, stack_b); + } + if (stack_b->premier->number >= stack_b->moyenne) + { + while (stack_b->premier->number != stack_b->max) + rotate(stack_b, 'b'); + } + else + { + while (stack_b->premier->number != stack_b->max) + reverse_rotate(stack_b, 'b'); + } + while (stack_a->length != length) + { + if (stack_a->dernier->number > stack_b->premier->number \ + && stack_a->dernier->number < stack_a->premier->number) + reverse_rotate(stack_a, 'a'); + push(stack_a, stack_b, 'a'); + } +} + +void turc(t_Liste *stack_a, t_Liste *stack_b) +{ + long length; + + length = stack_a->length; + push_two_number(stack_a, stack_b); + anti_25_ligne(stack_a, stack_b, length); +}