Exemplo n.º 1
0
void	ft_execute_route_2(int *l_a, t_pslist **ops, int *l_b)
{
	int small;
	int next;

	small = ft_find_smallest_number(l_a);
	next = ft_find_second_small_number(l_a);
	while (!ft_smallest_is_first(l_a))
	{
		if (ft_next_is_in_formation(l_a, next, small))
		{
			if (l_a[0] == next && l_a[1] == small)
				ft_swap(l_a, ops);
			else
			{
				if (l_a[0] != next)
					ft_rotate_first_to_end(l_a, ops);
				else
					ft_swap(l_a, ops);
			}
		}
		else
			ft_rotate_first_to_end(l_a, ops);
	}
	if (!ft_l_a_is_sorted(l_a))
		ft_pushb(l_b, l_a, ops);
}
Exemplo n.º 2
0
void	ft_selection(t_pile **a, t_pile **b, t_flag *f)
{
	int	i;

	i = 0;
	while (!ft_check_sort(a))
	{
		ft_prepa_push(a, b, f, "a-");
		if (!ft_check_sort(a))
		{
			ft_pushb(a, b, f);
			i++;
		}
	}
	while (i-- > 0)
		ft_pusha(a, b, f);
	while (*b)
	{
		ft_prepa_push(a, b, f, "b+");
		ft_pusha(a, b, f);
	}
}
Exemplo n.º 3
0
void	ft_sort(t_pile **a, t_pile **b, t_flag *f)
{
	int		piv;
	int		bef;
	int		i;
	t_pile	*tmp;

	bef = 0;
	i = 0;
	tmp = *a;
	piv = ft_piv(a, &bef);
	while (bef - i > 0)
	{
		if ((*a)->nb < piv)
		{
			ft_pushb(a, b, f);
			i++;
		}
		else
			ft_rotatea(a, b, f);
	}
	ft_selection(a, b, f);
}