/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */
--- /dev/null
- /* Updated: 2024/03/01 10:07:27 by ljiriste ### ########.fr */
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* special_a.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2024/03/01 09:45:01 by ljiriste #+# #+# */
- minind -= s->a.stack.size / 2;
++/* Updated: 2024/03/01 12:45:54 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "push_swap.h"
+#include "libft.h"
+#include <limits.h>
+#include <stddef.h>
+
+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 - 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 ;
+}