Exemplo n.º 1
0
int		lst_median(t_list *lst)
{
	t_list	*tmp_1;
	t_list	*tmp_2;
	int	nu_med;
	int	i;

	if (!lst)
		return (0);
	nu_med = ((t_pile*)(lst->content))->val;
	tmp_1 = lst;
	while (tmp_1)
	{
		tmp_2 = lst;
		i = 0;
		while (tmp_2)
		{
			if (((t_pile*)(tmp_2->content))->val\
				< ((t_pile*)(tmp_1->content))->val)
				i++;
			tmp_2 = tmp_2->next;
		}
		if (i == ft_lstcount(lst) / 2)
			nu_med = ((t_pile*)(tmp_1->content))->val;
		tmp_1 = tmp_1->next;
	}
	return (nu_med);
}
Exemplo n.º 2
0
int	get_limit_low(t_list *lst)
{
	int	lowest;
	t_list	*cpy;
	int	i;
	int	limit_low;

	if (!lst)
		return (0);
	lowest = get_lowest(lst);
	if (!(cpy = ft_lstcpy(lst, sizeof(t_pile))))
		return (0);
	while (((t_pile*)(cpy->content))->val != lowest)
		rotate(&cpy);
	limit_low = lowest;
	rotate(&cpy);
	i = 0;
	while (count_high(cpy, ((t_pile*)(cpy->content))->val)\
		== count_high(cpy, limit_low) - 1
		&& i++ < ft_lstcount(lst))
	{
		limit_low = ((t_pile*)(cpy->content))->val;
		rotate(&cpy);
	}
	return (limit_low);
}
Exemplo n.º 3
0
static void	sort_hint(t_hint *hint, int *i, int j)
{
	int	var;
	t_range	rg;

	bzero_rangval(&rg);
	init_rangval(&rg, hint->lst_data, j);
	var = ((t_pile*)(((t_list*)(*(hint->lst_a)))->content))->val;
	if (var >= rg.one && var < rg.two)
	{
		p_local(hint->lst_a, hint->lst_b, hint->mark);
		r_local(hint->lst_b, hint->mark);
		(*i)++;
	}
	else if (var >= rg.three && var < rg.four)
	{
		p_local(hint->lst_a, hint->lst_b, hint->mark);
		if (ft_lstcount(*(hint->lst_b)) > 1)
		{
				if (!check_next(*(hint->lst_b)))
					s_local(hint->lst_b, hint->mark);
		}
		(*i)++;
	}
	else
	{
		hint->mark->asc = 1;
		if (check_rothint(hint, rg))
			r_local(hint->lst_a, hint->mark);
		else
			rev_local(hint->lst_a, hint->mark);
		hint->mark->asc = 0;
	}
}
Exemplo n.º 4
0
static void	init_rangval(t_range *r_val, t_list *lst_data, int j)
{
	int	k;
	int	l;
	int	len;

	len = ft_lstcount(lst_data);
	k = len / 2 - j - 1;
	if (k < 0)
		return ;
	l = 0;
	while (l < k)
	{
		lst_data = lst_data->next;
		l++;
	}
	r_val->one = ((t_pile*)(lst_data->content))->val;
	r_val->two = ((t_pile*)(lst_data->next->content))->val;
	k = len / 2 + j;
	while (l < k)
	{
		lst_data = lst_data->next;
		l++;
	}
	r_val->three = ((t_pile*)(lst_data->content))->val;
	r_val->four = ((t_pile*)(lst_data->next->content))->val;
}
Exemplo n.º 5
0
t_map	*solve(t_list *list)
{
	t_map	*map;
	int		size;

	size = high_sqrt(ft_lstcount(list) * 4);
	map = map_new(size);
	while (!solve_map(map, list))
	{
		size++;
		free_map(map);
		map = map_new(size);
	}
	return (map);
}
Exemplo n.º 6
0
void	deal_hint(t_hint hint)
{
	int	i;
	int	j;
	int	len;

	len = ft_lstcount(hint.lst_lim);
	j = 0;
	while (j < len - 1)
	{
		i = 0;
		while (i < ((t_pile*)(hint.lst_lim->content))->val)
			sort_hint(&hint, &i, j);
		hint.lst_lim = hint.lst_lim->next;
		j++;
	}
	i = 0;
	while (i < ((t_pile*)(hint.lst_lim->content))->val)
		sort_hint_2(&hint, &i);
}
Exemplo n.º 7
0
static void		shell_exec_cmd(t_cmd *cmd)
{
	t_sh		*sh;
	t_list		*cur;
	t_exec_cmd	*ecmd;
	char		**argv;
	int			i;

	ecmd = (t_exec_cmd *)cmd;
	sh = shell_recover();
	argv = malloc(sizeof(char *) * (ft_lstcount(ecmd->argv) + 1));
	i = 0;
	cur = ecmd->argv;
	while (cur)
	{
		argv[i] = cur->content;
		i++;
		cur = cur->next;
	}
	argv[i] = NULL;
	sh->last_res = shell_boot(sh, sh->env_list, argv);
}
Exemplo n.º 8
0
size_t	ft_lstcount(t_list *lst)
{
	if (lst)
		return (1 + ft_lstcount(lst->next));
	return (0);
}