diff --git a/builds/algo.o b/builds/algo.o new file mode 100644 index 0000000..6082257 Binary files /dev/null and b/builds/algo.o differ diff --git a/builds/algo_bubble_sort.o b/builds/algo_bubble_sort.o new file mode 100644 index 0000000..3cc32d1 Binary files /dev/null and b/builds/algo_bubble_sort.o differ diff --git a/builds/print.o b/builds/print.o new file mode 100644 index 0000000..5801c25 Binary files /dev/null and b/builds/print.o differ diff --git a/builds/push.o b/builds/push.o new file mode 100644 index 0000000..f7a04b2 Binary files /dev/null and b/builds/push.o differ diff --git a/builds/push_swap.o b/builds/push_swap.o new file mode 100644 index 0000000..35bf7db Binary files /dev/null and b/builds/push_swap.o differ diff --git a/builds/reverse_rotate.o b/builds/reverse_rotate.o new file mode 100644 index 0000000..f62ccc1 Binary files /dev/null and b/builds/reverse_rotate.o differ diff --git a/builds/rotate.o b/builds/rotate.o new file mode 100644 index 0000000..100f4d8 Binary files /dev/null and b/builds/rotate.o differ diff --git a/builds/stop.o b/builds/stop.o new file mode 100644 index 0000000..37ff425 Binary files /dev/null and b/builds/stop.o differ diff --git a/builds/swap.o b/builds/swap.o new file mode 100644 index 0000000..6a3aa1f Binary files /dev/null and b/builds/swap.o differ diff --git a/includes/push_swap.h b/includes/push_swap.h index face171..7b921c5 100644 --- a/includes/push_swap.h +++ b/includes/push_swap.h @@ -9,6 +9,7 @@ typedef struct s_stack { int n; + int limit; struct s_stack *next; } t_stack; diff --git a/push_swap b/push_swap new file mode 100755 index 0000000..4658896 Binary files /dev/null and b/push_swap differ diff --git a/srcs/algo.c b/srcs/algo.c index 1191580..1a3767e 100644 --- a/srcs/algo.c +++ b/srcs/algo.c @@ -7,28 +7,104 @@ int last_element(t_stack *a) return (a->n); } -void recursive(t_stack **a, t_stack **b, t_list *solution, int last) +// size is initialized to 1 because the loop check the next element, so it will end one step before reaching it +// it checks the next one to avoid handle the first one with ->limit set to 1 +int sublist_size(t_stack *list) { - if (sublist_size(last, *a) > 5) - pivot_a_to_b(a, b, solution, last); - else + int size; + + if (list == NULL) + return (0); + size = 1; + while (list->next != NULL && list->next->limit != 1) { - sort_sublist_a(a, b, solution, last); - if (sublist_size(last, *b) < 5) - send_sublist_to_a(a, b, solution, last); - else - pivot_b_to_a(a, b, solution, last); + list = list->next; + size++; } + return (size); +} + +int nbr_element_smaller(t_stack *list, int size, int pivot) +{ + int nbr; + + nbr = 0; + while (size-- > 0) + { + if (list->n < pivot) + nbr++; + list = list->next; + } + return (nbr); +} + +// pivot is the smallest of the bigger group +int find_pivot(t_stack *list, int size) +{ + int pivot; + t_stack *head; + + pivot = list->n; + head = list; + while (head->next && nbr_element_smaller(list, size, pivot) != size / 2) + { + head = head->next; + pivot = head->n; + } + return (pivot); +} + +int divide_a(t_stack **a, t_stack **b, t_list *solution) +{ + int list_size; + int pivot; + + (void)b; + (void)solution; + list_size = sublist_size(*a); + pivot = find_pivot(*a, list_size); + ft_putnbrendl(list_size); + ft_putnbrendl(pivot); + return (0); +} + +int divide_b(t_stack **a, t_stack **b, t_list *solution) +{ + (void)a; + (void)b; + (void)solution; + return (0); +} + +void send_sublist_to_a(t_stack **a, t_stack **b, t_list *solution) +{ + (void)a; + (void)b; + (void)solution; +} + +void mini_sort(t_stack **a, t_stack **b, t_list *solution) +{ + (void)a; + (void)b; + (void)solution; } void hugo_sort(t_stack **a, t_stack **b, t_list *solution) { - (void)solution; - (void)b; - int last; - - last = last_element(*a); - recursive(*a, *b, solution, last); + divide_a(a, b, solution); +/* + if (sublist_size(*a) > 3) + divide_a(a, b, solution); + else if (sublist_size(*b) > 3) + { + mini_sort(a, b, solution); + divide_b(a, b, solution); + } + else + send_sublist_to_a(a, b, solution); + hugo_sort(a, b, solution); +*/ } // /* diff --git a/srcs/push_swap.c b/srcs/push_swap.c index 904bf78..d9fc949 100644 --- a/srcs/push_swap.c +++ b/srcs/push_swap.c @@ -29,9 +29,11 @@ t_stack *init_stack(int ac, char **av) if (!start) ps_stop(NULL, NULL, 2); start->n = ft_atoi(av[ac]); + start->limit = 0; start->next = tmp; tmp = start; } + start->limit = 1; return (start); } @@ -48,7 +50,7 @@ t_list *launch_algo(t_stack **a, t_stack **b, int flag) if (flag) fill_solution(solution, "start"); hugo_sort(a, b, solution); - //bubble_sort(a, b, solution); +// bubble_sort(a, b, solution); return (solution); }