Merge branch 'correct' into trunk
authorLukas Jiriste <ljiriste@student.42prague.com>
Fri, 1 Mar 2024 11:43:41 +0000 (12:43 +0100)
committerLukas Jiriste <ljiriste@student.42prague.com>
Fri, 1 Mar 2024 11:46:22 +0000 (12:46 +0100)
This merge fixes the sort before inclusion of LIS.
Now all problems should be only within LIS.

1  2 
src/push.c
src/special_a.c

diff --cc src/push.c
index 5368e3f94c250ee3bf594e881d6884281de8c798,303ee075b892cbd8ca3bc300d66fc46e6eb66ba8..69f0ab516f72faba566a5a269e77b878c277763c
@@@ -6,7 -6,7 +6,7 @@@
  /*   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       */
  /*                                                                            */
  /* ************************************************************************** */
  
diff --cc src/special_a.c
index 39f37765ebcb1a5608552149b1ef1f1d4086b111,0000000000000000000000000000000000000000..ea941bccce9c5830c2e1ec30755b2c864b0a5688
mode 100644,000000..100644
--- /dev/null
@@@ -1,77 -1,0 +1,77 @@@
- /*   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 ;
 +}