diff --git a/Makefile b/Makefile index 55cff5f..e671d4d 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ SRCS = push_swap.c \ ODIR = ./builds OBJS = $(SRCS:%.c=$(ODIR)/%.o) -CFLAGS = -I$(IDIR) -g3 -Wall -Wextra -Werror +CFLAGS = -I$(IDIR) -I./libft/includes/ -g3 -Wall -Wextra -Werror LFLAGS = -L$(LDIR) -l$(LIBS) diff --git a/builds/algo.o b/builds/algo.o index 5195668..9909ca5 100644 Binary files a/builds/algo.o and b/builds/algo.o differ diff --git a/builds/algo_bubble_sort.o b/builds/algo_bubble_sort.o index a898837..a481d60 100644 Binary files a/builds/algo_bubble_sort.o and b/builds/algo_bubble_sort.o differ diff --git a/builds/print.o b/builds/print.o index a3dd5d7..af044f1 100644 Binary files a/builds/print.o and b/builds/print.o differ diff --git a/builds/push.o b/builds/push.o index 2105527..f76518b 100644 Binary files a/builds/push.o and b/builds/push.o differ diff --git a/builds/push_swap.o b/builds/push_swap.o index 4dc54fc..0d35bb2 100644 Binary files a/builds/push_swap.o and b/builds/push_swap.o differ diff --git a/builds/reverse_rotate.o b/builds/reverse_rotate.o index f59aef6..0d77b92 100644 Binary files a/builds/reverse_rotate.o and b/builds/reverse_rotate.o differ diff --git a/builds/rotate.o b/builds/rotate.o index 474239d..d273614 100644 Binary files a/builds/rotate.o and b/builds/rotate.o differ diff --git a/builds/stop.o b/builds/stop.o index 29b1228..b9fe97b 100644 Binary files a/builds/stop.o and b/builds/stop.o differ diff --git a/builds/swap.o b/builds/swap.o index a468b0f..2ae8f0d 100644 Binary files a/builds/swap.o and b/builds/swap.o differ diff --git a/includes/push_swap.h b/includes/push_swap.h index e1443f8..face171 100644 --- a/includes/push_swap.h +++ b/includes/push_swap.h @@ -1,7 +1,7 @@ #ifndef PUSH_SWAP_H # define PUSH_SWAP_H -# include "../libft/includes/libft.h" +# include "libft.h" # include // read(), write(), sleep() # include // malloc(), free(), exit(), atoi() diff --git a/push_swap b/push_swap index edb7244..471f122 100755 Binary files a/push_swap and b/push_swap differ diff --git a/srcs/algo.c b/srcs/algo.c index 866cb21..57c8934 100644 --- a/srcs/algo.c +++ b/srcs/algo.c @@ -1,32 +1,28 @@ #include "push_swap.h" /* -** the nb compared to i in the while loop is the number -** of elements of the list that are competiting +** n is the nbr of elements of the list that are competiting */ -int match(t_stack **a) +int match(t_stack *a, int n) { - t_stack *tmp; int smaller; + int position; int i; - int j; - tmp = *a; - smaller = tmp->n; + smaller = a->n; + position = 0; i = 1; - j = 0; - while (i < 4) + while (i < n) { - tmp = tmp->next; - if (tmp->n < smaller) + a = a->next; + if (a->n < smaller) { - smaller = tmp->n; - j = i; + smaller = a->n; + position = i; } i++; } - ft_printf("%i [%i]\n", smaller, j); - return (j); + return (position); } void nb_to_top(t_stack **a, t_list *solution, int i) @@ -47,13 +43,36 @@ void nb_to_top(t_stack **a, t_list *solution, int i) } } +int last_element(t_stack *a) +{ + while (a->next) + a = a->next; + return (a->n); +} + void hugo_sort(t_stack **a, t_stack **b, t_list *solution) { - int i; +// int last; + int i; + int j; - i = match(a); - nb_to_top(a, solution, i); - (void)b; +// last = last_element(*a); + j = 5; + while (--j) + { + i = match(*a, 4); + nb_to_top(a, solution, i); + if ((*b) && (*a)->n < (*b)->n) + { + ra(a, &solution); + ft_putchar('t'); + } + else + { + ft_putchar('v'); + pb(b, a, &solution); + } + } } /* sa(a, &solution); diff --git a/srcs/print.c b/srcs/print.c index 36da8de..95fa14f 100644 --- a/srcs/print.c +++ b/srcs/print.c @@ -2,15 +2,23 @@ /* ** this function is called by actions like sa() -** it fills a new element on the chained list like this : -** name!a: nb nb nb nb nb!b: nb nb nb +** it fills a new str element on the chained list like this : ** -** it will later be printed like this ("!" is the char to split) : -** name -** a: nb nb nb nb nb -** b: nb nb nb +** b: nbb3 nbb2 nbb1!a: nba5 nba4 nba3 nba2 nba1!name +** (it fills it by the end, "!name" first, then "nba1" on its back, and so on) ** -** or only "name" if no flag -p +** so it can later be printed like that (in case of flag -p) : +** the "!" split the str : +** +** [0]b: nbb3 nbb2 nbb1 [1]a: nba5 nba4 nba3 nba2 nba1 [2]name +** +** to produce : +** +** [2]name +** [1] a: nba5 nba4 nba3 nba2 nba1 +** [0] b: nbb3 nbb2 nbb1 +** +** (if no flag -p, only [2]name is displayed) */ void fill_solution(t_list *solution, char *sp) { @@ -20,20 +28,21 @@ void fill_solution(t_list *solution, char *sp) a = *(t_stack **)(solution->content); b = *(t_stack **)(solution->next->content); - stack = ft_strjoinfree(ft_strdup(sp), ft_strdup("!a:")); + stack = ft_strjoinfree(ft_strdup("!"), ft_strdup(sp)); while (a != NULL) { - stack = ft_strjoinfree(stack, ft_strdup(" ")); - stack = ft_strjoinfree(stack, ft_itoa(a->n)); + stack = ft_strjoinfree(ft_itoa(a->n), stack); + stack = ft_strjoinfree(ft_strdup(" "), stack); a = a->next; } - stack = ft_strjoinfree(stack, ft_strdup("!b:")); + stack = ft_strjoinfree(ft_strdup("!a:"), stack); while (b != NULL) { - stack = ft_strjoinfree(stack, ft_strdup(" ")); - stack = ft_strjoinfree(stack, ft_itoa(b->n)); + stack = ft_strjoinfree(ft_itoa(b->n), stack); + stack = ft_strjoinfree(ft_strdup(" "), stack); b = b->next; } + stack = ft_strjoinfree(ft_strdup("b:"), stack); ft_lstadd_back(&solution, ft_lstnew(stack)); } @@ -48,11 +57,11 @@ void print_result(t_list *result, int flag) { i++; part = ft_split(result->content, '!'); - ft_printf("%s\n", part[0]); + ft_printf("%s\n", part[2]); if (flag) { ft_printf(" %s\n", part[1]); - ft_printf(" %s\n", part[2]); + ft_printf(" %s\n", part[0]); } result = result->next; free(part[0]);