Beispiel #1
0
Node * rearrange_lst (Node * head)
{
    // Do nothing if lenght of list is 0/1/2
    if (!head || !head->next || !head->next->next)
        return head;

    // Find middle point -- O(n)
    Node * slow = head;
    Node * fast = head->next;

    while (fast && fast->next)
    {
        slow = slow->next;
        fast = fast->next->next;
    }

    // Reverse second part of list -- O(n)
    Node * head_reversed = reverse_lst (slow->next);

    // Split list -- for merging
    slow->next = 0;

    // Merge two parts -- O(n)
    alternate_merge (head, head_reversed);

    return head;
}
Beispiel #2
0
int		main(void)
{
	t_salle	*h;
	t_init	all;
	char	*ptr;
	t_allp	*all_path;
	t_stap	st;

	if (get_next_line(0, &ptr) <= 0)
		return (0);
	all.nb_f = ((int)ft_strlen(ptr) <= 13) ? ft_atol(ptr) : -1;
	free(ptr);
	if (!(h = init_map(&all)) || all.nb_f <= 0 || all.nb_f >= 2147483648)
		exit_error("Error\n");
	h = reverse_lst(h);
	st.start = find_flag(h, "start");
	st.stop = find_flag(h, "end");
	st.nb_room = salle_len(h);
	all_path = NULL;
	if (!search_all_path(st, &all_path, &h))
		exit_error("Error\n");
	reinit_nb_hall(&all_path);
	verif_bouchon(&all_path);
	tri_path(&all_path);
	affiche(all);
	pass_fourmis(h, all_path, all.nb_f, all.color);
	return (0);
}