diff --git a/push_swap.c b/push_swap.c index f38336a..3303e4c 100644 --- a/push_swap.c +++ b/push_swap.c @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/11/23 16:48:12 by erey-bet #+# #+# */ -/* Updated: 2022/12/08 16:57:34 by erey-bet ### ########.fr */ +/* Updated: 2022/12/11 15:51:26 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -83,11 +83,11 @@ void push_swap_5(long *tab, int len) t_stack sb; sa.list = get_index(tab, len); - sa.len = len; - sb.list = malloc(sizeof(long) * (len + 1)); - if (sb.list == NULL) + if (sa.list == NULL) + return ; + sa.len = len; + if (init_sb(&sb, len) == NULL) return ; - sb.len = 0; while (sb.len != 2) { while (get_min(sa.list, sa.len) != 0) diff --git a/push_swap.h b/push_swap.h index ecc4b3c..c91da9b 100644 --- a/push_swap.h +++ b/push_swap.h @@ -44,6 +44,8 @@ int tab_malloc(int argc, char *argv[]); int put_error(void); char **set_only_space(char *argv[], int i); int if_there_is_double(long *tab, int y); +void *init_sb(t_stack *sb, int len); + // Parsing int parsing(int argc, char *argv[], long *tab); diff --git a/tools_2.c b/tools_2.c index 8014912..d6f2b5e 100644 --- a/tools_2.c +++ b/tools_2.c @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/12/09 15:54:00 by erey-bet #+# #+# */ -/* Updated: 2022/12/09 15:54:03 by erey-bet ### ########.fr */ +/* Updated: 2022/12/11 15:51:37 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -48,3 +48,12 @@ int if_there_is_double(long *tab, int y) } return (0); } + +void *init_sb(t_stack *sb, int len) +{ + sb->list = malloc(sizeof(long) * (len + 1)); + if (sb->list == NULL) + return (NULL); + sb->len = 0; + return (sb); +}