Example #1
0
void	morc_tri_r(t_all *res, int debut, int fin, int base)
{
	int	i;
	int	ind;

	i = debut;
	ind = 0;
	while (i++ <= fin)
		if (res->a->pile[res->a->len - 1] < base)
			push_b(res);
		else
		{
			if (res->a->pile[res->a->len - 1] == base)
			{
				push_b(res);
				rotate_b(res);
			}
			else
			{
				rotate_a(res);
				ind++;
			}
		}
	if ((fin - debut) != (res->a->len + res->b->len - 1))
		while (ind-- > 0)
			reverse_rotate_a(res);
	reverse_rotate_b(res);
}
Example #2
0
void	reverse_rotate_r(t_env *env, t_flags *flag)
{
	reverse_rotate_a(env, flag);
	reverse_rotate_b(env, flag);
	env->count -= 1;
	ft_putstr("\033[35mrrr \033[37m");
	if (flag->v == 1)
		stack_status(env);
}
Example #3
0
static void		first_pile_check(t_pushswap *data)
{
	if (data->length_a == 3
			&& check_pile_reverse(data->pile_a, data->length_a))
	{
		reverse_rotate_a(data, 0);
		swap_a(data, 0);
	}
	if (data->pile_a[0] < data->pile_a[1])
		check_swap_beg(data);
	if (data->pos_smallest_a == data->length_a - 2)
		check_swap(data);
}
Example #4
0
static void		check_swap_beg(t_pushswap *data)
{
	int		i;

	if (data->length_a == 2 || data->length_a == 3)
		return ;
	i = 3;
	while (i < data->length_a)
	{
		if (data->pile_a[i - 1] < data->pile_a[i]
				|| data->pile_a[i - 1] > data->pile_a[1])
			return ;
		i++;
	}
	rotate_a(data, 0);
	rotate_a(data, 0);
	swap_a(data, 0);
	if (check_pile(data->pile_a, data->length_a))
		return ;
	reverse_rotate_a(data, 0);
	reverse_rotate_a(data, 0);
}
Example #5
0
static void		put_smallest_last(t_pushswap *data)
{
	int		i;

	i = 0;
	if (data->pos_smallest_a < data->length_a / 2)
	{
		while (data->pos_smallest_a != data->length_a - 1)
			rotate_a(data, 0);
	}
	else
	{
		while (data->pos_smallest_a != data->length_a - 1)
			reverse_rotate_a(data, 0);
	}
}