From e0447c21e9864155cdc362daa9f721f862d7efe2 Mon Sep 17 00:00:00 2001 From: SaladBunda Date: Mon, 8 Apr 2024 17:39:55 +0000 Subject: [PATCH] workign on leaks --- Makefile | 2 +- bonus/{extra_sort.c => extra_sort_bonus.c} | 4 +- bonus/ft_split_bonus.c | 102 ++++++++++++++++++ bonus/main.c | 118 +++++++++++++++++++++ bonus/operations.c | 61 +++++++++++ bonus/operations2.c | 89 ++++++++++++++++ bonus/push_swap.h | 53 +++++++++ bonus/range.c | 112 +++++++++++++++++++ bonus/sort.c | 100 +++++++++++++++++ bonus/util_func1.c | 67 ++++++++++++ bonus/util_func2.c | 76 +++++++++++++ push_swap | Bin 22664 -> 22576 bytes srcs/extra_sort.o | Bin 0 -> 1992 bytes srcs/main.c | 12 ++- srcs/main.o | Bin 2244 -> 2480 bytes srcs/range.o | Bin 0 -> 2480 bytes srcs/sort.o | Bin 0 -> 1740 bytes 17 files changed, 790 insertions(+), 6 deletions(-) rename bonus/{extra_sort.c => extra_sort_bonus.c} (92%) create mode 100644 bonus/ft_split_bonus.c create mode 100644 bonus/main.c create mode 100644 bonus/operations.c create mode 100644 bonus/operations2.c create mode 100644 bonus/push_swap.h create mode 100644 bonus/range.c create mode 100644 bonus/sort.c create mode 100644 bonus/util_func1.c create mode 100644 bonus/util_func2.c create mode 100644 srcs/extra_sort.o create mode 100644 srcs/range.o create mode 100644 srcs/sort.o diff --git a/Makefile b/Makefile index 4212c01..ddb0838 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -SRCS = main.c ft_split.c util_func1.c util_func2.c operations.c operations2.c operations3.c sort.c range.c extra_sort.c +SRCS = main.c ft_split.c util_func1.c util_func2.c operations.c operations2.c sort.c range.c extra_sort.c # SRCB = DIR = ./srcs/ BONUS_DIR = ./bonus/ diff --git a/bonus/extra_sort.c b/bonus/extra_sort_bonus.c similarity index 92% rename from bonus/extra_sort.c rename to bonus/extra_sort_bonus.c index 447d143..b1624a5 100644 --- a/bonus/extra_sort.c +++ b/bonus/extra_sort_bonus.c @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: ael-maaz +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2024/04/08 16:59:37 by ael-maaz #+# #+# */ -/* Updated: 2024/04/08 16:59:38 by ael-maaz ### ########.fr */ +/* Created: 2024/04/08 16:59:08 by ael-maaz #+# #+# */ +/* Updated: 2024/04/08 16:59:16 by ael-maaz ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/bonus/ft_split_bonus.c b/bonus/ft_split_bonus.c new file mode 100644 index 0000000..558f34e --- /dev/null +++ b/bonus/ft_split_bonus.c @@ -0,0 +1,102 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ael-maaz +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/12/10 16:02:02 by ael-maaz #+# #+# */ +/* Updated: 2024/04/01 22:35:05 by ael-maaz ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "push_swap.h" + +static int word_c(char *str, char c) +{ + int i; + int count; + + i = 0; + count = 0; + while (str && str[i] == c && str[i]) + i++; + while (str && str[i]) + { + count++; + while (str[i] != c && str[i]) + i++; + while (str[i] == c && str[i]) + i++; + } + return (count); +} + +static char **freef(char **tab, int j) +{ + while (j >= 0) + free(tab[j--]); + free(tab); + return (NULL); +} + +static int char_c(char *str, char c) +{ + int i; + + i = 0; + while (str[i] && str[i] != c) + i++; + return (i); +} + +static char *strdup_i(const char *s1, char c, int *index) +{ + char *p; + int i; + int j; + int word_size; + + j = 0; + i = *index; + word_size = char_c((char *)&s1[i], c); + p = (char *)malloc(sizeof(char) * (word_size + 1)); + if (!p) + return (NULL); + ft_memcpy(p, (char *)s1 + i, (size_t)word_size); + while (j < word_size) + { + j++; + (*index)++; + } + p[word_size] = '\0'; + return (p); +} + +char **ft_split(char const *s, char c) +{ + char **tab; + int j; + int i; + + i = 0; + j = 0; + if (!s) + return (NULL); + tab = malloc(sizeof(char *) * (word_c((char *)s, c) + 1)); + if (!tab) + return (NULL); + while (s[i] && s[i] == c) + i++; + while (s[i] && j < word_c((char *)s, c)) + { + tab[j] = strdup_i(s, c, &i); + if (!tab[j]) + return (freef(tab, j)); + j++; + while (s[i] && s[i] == c) + i++; + } + tab[word_c((char *)s, c)] = NULL; + return (tab); +} diff --git a/bonus/main.c b/bonus/main.c new file mode 100644 index 0000000..23dd214 --- /dev/null +++ b/bonus/main.c @@ -0,0 +1,118 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ael-maaz +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/04/01 16:58:38 by ael-maaz #+# #+# */ +/* Updated: 2024/04/08 17:24:17 by ael-maaz ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "push_swap.h" + +int fill_stack(char **av, int ac, t_stack *stack_a, int i) +{ + int j; + int k; + char **arg; + int error; + + error = 0; + k = stack_a->size - 1; + stack_a->top = -1; + while (++i < ac) + { + j = -1; + if (av[i][0] == 0) + error = 1; + arg = ft_split(av[i], ' '); + while (arg[++j]) + { + stack_a->top++; + stack_a->stack[k--] = ft_atoi(arg[j], &error); + } + } + if (error == 0) + return (0); + else + return (1); +} + +int duplicates(t_stack stack_a) +{ + int i; + int j; + + i = 0; + while (i < stack_a.size) + { + j = 0; + while (j < i) + { + if (stack_a.stack[j] == stack_a.stack[i]) + return (0); + j++; + } + i++; + } + return (1); +} + +int init_stacks(char **av, int ac, t_stack *stack_a, t_stack *stack_b) +{ + int i; + int j; + char **arg; + int error; + + i = 0; + stack_a->size = 0; + while (++i < ac) + { + j = -1; + arg = ft_split(av[i], ' '); + while (arg[++j]) + stack_a->size++; + } + stack_a->stack = malloc(sizeof(int) * stack_a->size); + stack_b->size = stack_a->size; + stack_b->stack = malloc(sizeof(int) * stack_b->size); + stack_b->top = -1; + error = fill_stack(av, ac, stack_a, 0); + return (error); +} + +// void print_stacks(t_stack a,t_stack b) +// { +// printf("-----------------stack a-----------\n"); +// while(a.top >= 0) +// printf("%d\n", a.stack[a.top--]); +// printf("-----------------stack b------------\n"); +// while(b.top >= 0) +// printf("%d\n", b.stack[b.top--]); +// } + +int main(int ac, char **av) +{ + t_stack a; + t_stack b; + + if (ac > 1) + { + get_range(40); + if (init_stacks(av, ac, &a, &b) == 1) + { + write(2, "Error\n", 6); + return (0); + } + if (duplicates(a) == 0) + return (write(2, "Error\n", 6), 0); + if (is_sorted(&a) == 0) + return (0); + bubble_sort(&a); + range(&a, &b); + system("leaks push_swap"); + } +} diff --git a/bonus/operations.c b/bonus/operations.c new file mode 100644 index 0000000..e5faa6c --- /dev/null +++ b/bonus/operations.c @@ -0,0 +1,61 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* operations.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ael-maaz +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/04/03 02:34:02 by ael-maaz #+# #+# */ +/* Updated: 2024/04/05 23:02:35 by ael-maaz ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "push_swap.h" + +void pb(t_stack *a, t_stack *b) +{ + if (a->top > -1) + { + b->top++; + b->stack[b->top] = a->stack[a->top]; + a->top--; + ft_putstr("pb\n"); + } +} + +void pa(t_stack *a, t_stack *b) +{ + if (b->top > -1) + { + a->top++; + a->stack[a->top] = b->stack[b->top]; + b->top--; + ft_putstr("pa\n"); + } +} + +void sa(t_stack *a) +{ + int tmp; + + if (a->top > 0) + { + tmp = a->stack[a->top]; + a->stack[a->top] = a->stack[a->top -1]; + a->stack[a->top -1] = tmp; + ft_putstr("sa\n"); + } +} + +void sb(t_stack *b) +{ + int tmp; + + if (b->top > 0) + { + tmp = b->stack[b->top]; + b->stack[b->top] = b->stack[b->top - 1]; + b->stack[b->top -1] = tmp; + ft_putstr("sb\n"); + } +} diff --git a/bonus/operations2.c b/bonus/operations2.c new file mode 100644 index 0000000..04c762c --- /dev/null +++ b/bonus/operations2.c @@ -0,0 +1,89 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* operations2.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ael-maaz +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/04/03 16:37:55 by ael-maaz #+# #+# */ +/* Updated: 2024/04/05 23:04:30 by ael-maaz ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "push_swap.h" + +void rra(t_stack *a) +{ + int tmp; + int i; + + i = 0; + if (a->top > 0) + { + tmp = a->stack[0]; + while (i < a->top) + { + a->stack[i] = a->stack[i + 1]; + i++; + } + a->stack[a->top] = tmp; + ft_putstr("rra\n"); + } +} + +void rrb(t_stack *b) +{ + int tmp; + int i; + + i = 0; + if (b->top > 0) + { + tmp = b->stack[0]; + while (i < b->top) + { + b->stack[i] = b->stack[i + 1]; + i++; + } + b->stack[b->top] = tmp; + ft_putstr("rrb\n"); + } +} + +void ra(t_stack *a) +{ + int tmp; + int i; + + i = a->top; + if (a->top > 0) + { + tmp = a->stack[a->top]; + while (i > 0) + { + a->stack[i] = a->stack[i - 1]; + i--; + } + a->stack[0] = tmp; + ft_putstr("ra\n"); + } +} + +void rb(t_stack *b) +{ + int tmp; + int i; + + i = b->top; + if (b->top > 0) + { + tmp = b->stack[b->top]; + while (i > 0) + { + b->stack[i] = b->stack[i - 1]; + i--; + } + b->stack[0] = tmp; + ft_putstr("rb\n"); + } +} diff --git a/bonus/push_swap.h b/bonus/push_swap.h new file mode 100644 index 0000000..ba1830f --- /dev/null +++ b/bonus/push_swap.h @@ -0,0 +1,53 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* push_swap.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ael-maaz +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/04/01 16:59:48 by ael-maaz #+# #+# */ +/* Updated: 2024/04/07 22:15:42 by ael-maaz ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef PUSH_SWAP_H +# define PUSH_SWAP_H + +# include +# include +# include +# include +# include + +typedef struct s_stack +{ + int *stack; + int top; + int size; +} t_stack; + +void ft_putchar(char c); +void *ft_memcpy(void *dst, const void *src, size_t n); +void ft_putstr(char *s); +void ft_putnbr(int n); +void pb(t_stack *a, t_stack *b); +void pa(t_stack *a, t_stack *b); +void sa(t_stack *a); +void sb(t_stack *b); +void rra(t_stack *a); +void rrb(t_stack *b); +void ra(t_stack *a); +void rb(t_stack *b); +void bubble_sort(t_stack *a); +void range(t_stack *a, t_stack *b); +void sort_three(t_stack *a); +void sort_five(t_stack *a, t_stack *b); +void sort_four(t_stack *a, t_stack *b); +int ft_strlen(char *s); +char **ft_split(char const *s, char c); +int ft_atoi(char *s, int *error); +int is_sorted(t_stack *a); +int get_max_index(t_stack *b); +int get_range(int size); + +#endif \ No newline at end of file diff --git a/bonus/range.c b/bonus/range.c new file mode 100644 index 0000000..951fa44 --- /dev/null +++ b/bonus/range.c @@ -0,0 +1,112 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* range.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ael-maaz +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/04/04 01:07:40 by ael-maaz #+# #+# */ +/* Updated: 2024/04/07 22:09:56 by ael-maaz ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "push_swap.h" + +int get_max_index(t_stack *x) +{ + int i; + int max[2]; + + max[0] = x->stack[x->top]; + i = x->top; + max[1] = i; + while (i >= 0) + { + if (max[0] < x->stack[i]) + { + max[0] = x->stack[i]; + max[1] = i; + } + i--; + } + return (max[1]); +} + +int get_median(t_stack *b) +{ + int i; + + i = (b->top + 1) / 2; + return (i); +} + +void pushing_back(t_stack *a, t_stack *b, int median, int index) +{ + while (b->top > -1) + { + median = get_median(b); + index = get_max_index(b); + if (index < median) + { + while (index != b->top) + { + rrb(b); + index = get_max_index(b); + } + pa(a, b); + } + else + { + while (index != b->top) + { + rb(b); + index = get_max_index(b); + } + pa(a, b); + } + } +} + +void push_to_b(t_stack *a, t_stack *b, int rng) +{ + int min; + int max; + + min = 0; + while (a->top > -1) + { + max = min + rng; + if (a->stack[a->top] >= min && a->stack[a->top] <= max) + { + pb(a, b); + if (max < a->size) + min++; + } + else if (a->stack[a->top] > max) + { + ra(a); + } + else if (a->stack[a->top] < min) + { + pb(a, b); + rb(b); + if (max < a->size) + min++; + } + } +} + +void range(t_stack *a, t_stack *b) +{ + if (a->size > 5) + push_to_b(a, b, get_range(a->size)); + else if (a->size == 5) + sort_five(a, b); + else if (a->size == 4) + sort_four(a, b); + else if (a->size == 3) + sort_three(a); + else if (a->size == 2) + sa(a); + pushing_back(a, b, 0, 0); +} diff --git a/bonus/sort.c b/bonus/sort.c new file mode 100644 index 0000000..df1b173 --- /dev/null +++ b/bonus/sort.c @@ -0,0 +1,100 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* sort.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ael-maaz +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/04/03 17:46:57 by ael-maaz #+# #+# */ +/* Updated: 2024/04/05 23:06:27 by ael-maaz ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "push_swap.h" + +int is_sorted(t_stack *a) +{ + int i; + + i = 0; + while (i < a->size - 1) + { + if (a->stack[i] < a->stack[i + 1]) + return (1); + i++; + } + return (0); +} + +void swap(int *a, int *b) +{ + int tmp; + + tmp = *a; + *a = *b; + *b = tmp; +} + +void sort(int *arr, int size) +{ + int swapped; + int i; + + i = 0; + swapped = 1; + while (swapped > 0) + { + swapped = 0; + i = 0; + while (i < size - 1) + { + if (arr[i] > arr[i + 1]) + { + swap(&arr[i], &arr[i + 1]); + swapped = 1; + } + i++; + } + size--; + } +} + +void put_indexes(int *arr, t_stack *a) +{ + int i; + int j; + + i = 0; + while (i < a->size) + { + j = 0; + while (j < a->size) + { + if (a->stack[i] == arr[j]) + { + a->stack[i] = j; + break ; + } + j++; + } + i++; + } +} + +void bubble_sort(t_stack *a) +{ + int *arr; + int i; + + i = 0; + arr = malloc(sizeof(int) * a->size); + if (!arr) + return ; + while (i < a->size) + { + arr[i] = a->stack[i]; + i++; + } + sort(arr, a->size); + put_indexes(arr, a); +} diff --git a/bonus/util_func1.c b/bonus/util_func1.c new file mode 100644 index 0000000..fb434b2 --- /dev/null +++ b/bonus/util_func1.c @@ -0,0 +1,67 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* util_func1.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ael-maaz +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/12/11 19:46:58 by ael-maaz #+# #+# */ +/* Updated: 2024/04/05 22:54:48 by ael-maaz ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "push_swap.h" + +void ft_putchar(char c) +{ + write(1, &c, 1); +} + +static void recurs(long n) +{ + if (n < 10) + ft_putchar(n + '0'); + else + { + recurs(n / 10); + ft_putchar((n % 10) + '0'); + } +} + +void ft_putnbr(int n) +{ + long nbr; + + nbr = (long)n; + if (nbr >= 0) + recurs(nbr); + else if (n < 0) + { + ft_putchar('-'); + recurs(-nbr); + } +} + +void ft_putstr(char *s) +{ + int i; + + i = 0; + while (s[i]) + write(1, &s[i++], 1); +} + +void *ft_memcpy(void *dst, const void *src, size_t n) +{ + size_t i; + + if (!dst && !src) + return (NULL); + i = 0; + while (i < n) + { + ((unsigned char *)dst)[i] = ((unsigned char *)src)[i]; + i++; + } + return (dst); +} diff --git a/bonus/util_func2.c b/bonus/util_func2.c new file mode 100644 index 0000000..5cbce90 --- /dev/null +++ b/bonus/util_func2.c @@ -0,0 +1,76 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* util_func2.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ael-maaz +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/12/04 22:26:52 by ael-maaz #+# #+# */ +/* Updated: 2024/04/07 22:48:36 by ael-maaz ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "push_swap.h" + +int ft_strlen(char *s) +{ + int count; + + count = 0; + while (s[count] != '\0') + { + count++; + } + return (count); +} + +int fcmp(const char *s1, const char *s2) +{ + int i; + + i = 0; + while ((s1[i] != '\0' || s2[i] != '\0')) + { + if ((unsigned char)s1[i] > (unsigned char)s2[i]) + return (1); + else if ((unsigned char)s1[i] < (unsigned char)s2[i]) + return (-1); + i++; + } + return (0); +} + +int get_range(int size) +{ + int range; + + range = 0.045 * size + 10.5; + return (range); +} + +int ft_atoi(char *s, int *error) +{ + int i; + int sign; + long long num; + + i = 0; + if (fcmp(s, "-0") == 0 || fcmp(s, "+0") == 0 || fcmp(s, "0") == 0) + return (0); + num = 0; + sign = 1; + while ((s[i] >= 9 && s[i] <= 13) || s[i] == 32) + i++; + if (s[i] == '-' || s[i] == '+') + { + if (s[i++] == '-') + sign = -1; + } + while (s[i] >= '0' && s[i] <= '9') + { + num = num * 10 +(s[i++] - 48); + } + if (s[i] != '\0' || num == 0 || num > 2147483647 || num < -2147483648) + *error = -1; + return (num * sign); +} diff --git a/push_swap b/push_swap index bece8bb708a199019f3222307f66673f58420965..ea675d1bf72f9c15f7ecd1b9ae4197cdbf674821 100755 GIT binary patch delta 2868 zcmZuz3s6+o8UD}RMKq$zf(Qnb1%dDqsEMs9K9=gXHz;NS71{=27dBxlkIn9)W;%42 zK@;hQ3GtX%le8hzX*;!cB*DhENn5B+w3gPTaWba1)2*4Ymp*1zGFn9H_B(qIj$^xU z{&T+Xf1LmR=iGDd;kVhy2pbBgSW<}?5nauMz|WHU^0iGVb7eZaN+)TqjIU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IWE|8V__dNA4TW@;?d*!kA>1+1UH L*51e??N9#)I9$X< diff --git a/srcs/extra_sort.o b/srcs/extra_sort.o new file mode 100644 index 0000000000000000000000000000000000000000..745a872bebeab45e29546d40110074591e9a78e4 GIT binary patch literal 1992 zcmbtVO=uHA6rR-BrZ(;7Q2armIe1+WL8w%rMVIcuK$QjyrH*Nuw6Q-4`OzW<3u$ea z(GsCo4<0;uDPAldq)=}Ke=eeUDH5T9DmfGkqK)6%oozR13k4r}^UZtn-kWdU>~7xw z{;}1-nClS30Chu`XyS)LPC(nq-bdCc5%O8a*fwf1Qn}1HPe&%x6ln?Py;@(dZSCNT zI%`h#h|BU}#*UK9&87%!;XE84PlUp0o|(8Cn;7E!>J@v9a8cHolFm64BQA-0t1hN8 z!V2I#GQy+D(0IhQtNERk2U)U~nFqY=vyrQbu@Sjs!a0n`p=Mi@BaD$kXjAg%!NUve zL6atd$Y(uJr_lLHJx=EV=Rw{0uIDy8*Wyf$FB=Co@g`O0AC}!jxC_@U>bhl5#A*uP$H*! ztbzy>aJXEyz?4T9ktsAR29VK+lNLJMPn7v%WBUlo_f`LwGh1_z*&nx(Jr_3m*+_O_?G7LR$l0|GX0+J_=XyVYP!gj%&oUqtGy<-sLg4+p9kYp_n&;K z$n6*=C$mTPuxd?qeQ`d>fS3EM=Viw1KI?w@wu^n%TV;LMz3a?1>2vwK4IZj_8vawz z#Xo2>MDk;-tHt-Q?s79;V^b&&k16Z>YsE>Pd&Z3+t|a3m-#z0NsNR-UPx9Us_YCL4 zCq!KU;-}7H!1qE;0wHP)h%b-Y55zO1o|pb+AmvdKzGLbyoR#vvS$$N$04Z-3NO{kt z|31(SyB~-*@zPgpLih^UL~%g$L`?uG|E9F*ohSb-AX4i)CHf@-Oh0X-V6g97m9~9< zK55(c-7al_DYOsOu!Zi#Y2T=^Q#JNrjUBJCZ`at-8k_OqNScqwCOH0-B9n}#;>k3R z#xqI$1@crn6dvW_kx?EE#m4N#*qw-+rbm(y%$Gdj literal 0 HcmV?d00001 diff --git a/srcs/main.c b/srcs/main.c index 8c0e266..815574e 100644 --- a/srcs/main.c +++ b/srcs/main.c @@ -6,7 +6,7 @@ /* By: ael-maaz +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/01 16:58:38 by ael-maaz #+# #+# */ -/* Updated: 2024/04/07 22:08:41 by ael-maaz ### ########.fr */ +/* Updated: 2024/04/08 17:34:55 by ael-maaz ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,12 +32,13 @@ int fill_stack(char **av, int ac, t_stack *stack_a, int i) { stack_a->top++; stack_a->stack[k--] = ft_atoi(arg[j], &error); + free(arg[j]); } } if (error == 0) - return (0); + return (free(arg), 0); else - return (1); + return (free(arg), 1); } int duplicates(t_stack stack_a) @@ -74,8 +75,12 @@ int init_stacks(char **av, int ac, t_stack *stack_a, t_stack *stack_b) j = -1; arg = ft_split(av[i], ' '); while (arg[++j]) + { stack_a->size++; + free(arg[j]); + } } + free(arg); stack_a->stack = malloc(sizeof(int) * stack_a->size); stack_b->size = stack_a->size; stack_b->stack = malloc(sizeof(int) * stack_b->size); @@ -113,5 +118,6 @@ int main(int ac, char **av) return (0); bubble_sort(&a); range(&a, &b); + system("leaks push_swap"); } } diff --git a/srcs/main.o b/srcs/main.o index 1b28078f6ebd7357ff6d1a8d5cabf50a80406ab5..84215f761a7e5a2aa9b9616e4ffd0fb7d0960839 100644 GIT binary patch delta 977 zcmZWnO-NKh9G`jad%J6Eej&Riwn~&%JSfUk%8!y)BN1$t9V%HCT`5{w-BrwktYII# zmP-A12s#yXPv~HsGMCnyUIK#-MhI(kh)zO={pP(V$@V|I-~2vi=Kp3UQ~J7ms=Z98 z%&L0DMxjo3wN`8t{8L>R4!Ri&Ousr-wr%)rpVes7-&^;T$P8-2`ZCs}F(y|y;-NGA zMCp`c&pGxSnY^tiL40$n;KJg$gB(Bs^iQ=PrrGsZErd;KhD66!mM7n!X^p32E z^r>Gtxyt&?*4CCt8&EGub38T2|K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