From: Lukas Jiriste Date: Fri, 1 Mar 2024 11:43:41 +0000 (+0100) Subject: Merge branch 'correct' into trunk X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=f2ec98099f159063045b42c5d3abf506227e9134;p=42%2Fpush_swap.git Merge branch 'correct' into trunk This merge fixes the sort before inclusion of LIS. Now all problems should be only within LIS. --- f2ec98099f159063045b42c5d3abf506227e9134 diff --cc src/push.c index 5368e3f,303ee07..69f0ab5 --- a/src/push.c +++ b/src/push.c @@@ -6,7 -6,7 +6,7 @@@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/24 13:17:32 by ljiriste #+# #+# */ - /* Updated: 2024/03/01 10:07:27 by ljiriste ### ########.fr */ -/* Updated: 2024/03/01 11:59:30 by ljiriste ### ########.fr */ ++/* Updated: 2024/03/01 12:43:14 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ diff --cc src/special_a.c index 39f3776,0000000..ea941bc mode 100644,000000..100644 --- a/src/special_a.c +++ b/src/special_a.c @@@ -1,77 -1,0 +1,77 @@@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* special_a.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ljiriste +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/01 09:45:01 by ljiriste #+# #+# */ - /* Updated: 2024/03/01 10:07:27 by ljiriste ### ########.fr */ ++/* Updated: 2024/03/01 12:45:54 by ljiriste ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "push_swap.h" +#include "libft.h" +#include +#include + +void rotate_a_to_sort(t_stacks *s) +{ + size_t minind; + t_action *print_action; + + minind = find_minind(&s->a); + if (minind <= s->a.stack.size / 2) + print_action = print_rotate; + else + { - minind -= s->a.stack.size / 2; ++ minind = s->a.stack.size - minind; + print_action = print_reverse_rotate; + } + while (minind > 0) + { + print_action(s, a); + --minind; + } + return ; +} + +void isolate_lis_in_a(t_stacks *s, t_stack *lis) +{ + while (s->a.stack.size > lis->stack.size && s->a.stack.size > 3) + { + if (stack_top(lis) == stack_top(&s->a)) + { + stack_rotate(lis, 1); + print_rotate(s, a); + } + else + print_push(s, b); + } + return ; +} + +void a_sort_three_or_less(t_stacks *s) +{ + int last; + int max; + size_t steps_to_smaller; + size_t i; + + i = 0; + last = stack_top(&s->a); + max = INT_MIN; + steps_to_smaller = 0; + while (i < s->a.stack.size) + { + stack_rotate(&s->a, 1); + steps_to_smaller += (stack_top(&s->a) < last); + last = stack_top(&s->a); + if (max < stack_top(&s->a)) + max = stack_top(&s->a); + ++i; + } + if (steps_to_smaller == 2) + print_swap(s, a); + return ; +}