From: Lukas Jiriste Date: Tue, 5 Mar 2024 10:57:32 +0000 (+0100) Subject: Disable using LIS for very small input X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=63cf3a6aff639f6ed60aa5a6af2b84582388d99b;p=42%2Fpush_swap.git Disable using LIS for very small input When sorting lists smaller than 7 elements, the LIS algorithm performes worse than the push-only one. This is probably caused by additional rotations, that are needed to isolate LIS in stack A. --- diff --git a/src/push.c b/src/push.c index 909bffd..ac06c0b 100644 --- a/src/push.c +++ b/src/push.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/24 13:17:32 by ljiriste #+# #+# */ -/* Updated: 2024/03/05 09:40:03 by ljiriste ### ########.fr */ +/* Updated: 2024/03/05 11:54:36 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,6 +43,13 @@ void get_push_indeces(t_stacks *s, int *ind_a, int *ind_b) return ; } +void push_all_but_three(t_stacks *s) +{ + while (s->a.stack.size > 3) + print_push(s, b); + return ; +} + void sort(t_stacks *s) { int ind_a; @@ -50,9 +57,14 @@ void sort(t_stacks *s) t_stack lis; init_stack(&lis); - get_circular_lis(&lis, &s->a); - isolate_lis_in_a(s, &lis); - free_stack(&lis); + if (s->a.stack.size > 6) + { + get_circular_lis(&lis, &s->a); + isolate_lis_in_a(s, &lis); + free_stack(&lis); + } + else + push_all_but_three(s); if (lis.stack.size < 3) a_sort_three_or_less(s); while (s->b.stack.size > 0)