Exemple #1
0
t_list_i	*push_swap(t_list_i *list)
{
	t_list_i	*pile_b;
	t_list_i	*last_item;

	pile_b = NULL;
	last_item = NULL;
	while ((test_sort_croissant(list) == 0) || pile_b)
	{
		last_item = can_we_rotate(list);
		if (last_item && list->next && list->next->next)
			list = rotate_a(list);
		if (list->c < list->next->c)
			list = swap_a(list);
		if (list->c > list->next->c && (test_sort_croissant(list) == 0)
			&& list->next && list->next->next != NULL)
			pile_b = push_b(&list, pile_b);
		if (pile_b && pile_b->next && pile_b->c > pile_b->next->c)
			pile_b = swap_b(pile_b);
		if (pile_b && pile_b->next && test_sort_decroissant(pile_b) &&
			test_sort_croissant(list))
			list = push_a(list, &pile_b);
		if (test_sort_croissant(list) && pile_b && pile_b->next == NULL)
			list = push_a(list, &pile_b);
	}
	return (list);
}
int dfs(long a,long b,char ch)
{
	t1=t2=0;
	long c,d,k;
	push_a(0);
	push_b(0);
	push_a(a+1);
	push_b(b+1);
	vis[a][b]=fill;
	while(a=pop_a())
	{
		b=pop_b();
		a--;b--;
		c=a;d=b;
		for(k=0;k<6;k++)
		{
			 c=a+x[k];
			  d=b+y[k];
			if(c>=0&&c<n&&d>=0&&d<n&&!vis[c][d]&&grid[c][d]==ch)
			{
		    	push_a(c+1);
				push_b(d+1);
			    vis[c][d]=fill;
				if(fu==1&&d==n-1)
					return 1;
				else if(fu==2&&c==n-1)
					return 1;

			}
		}
	}
	return 0;
}
long dfs(long a,long b,char im)
{
	long c,d,k,count=0;
	push_a(0);
	push_b(0);
	push_a(a+1);
	push_b(b+1);
	vis[a][b]=1;
	while(a=pop_a())
	{
		count++;
		b=pop_b();
		a--;b--;
		c=a;d=b;
		for(k=0;k<8;k++)
		{
			 c=a+x[k];
			  d=b+y[k];
			if(c>=0&&c<m&&d>=0&&d<n&&!vis[c][d]&&grid[c][d]==im)
			{
		    	push_a(c+1);
				push_b(d+1);
			    vis[c][d]=1;
			  
			}
			 
			  
		}
	}
	return count;
}
void	decroissant(t_all *i)
{
	while (i->a->len > 2)
	{
		push_b(i);
		if (i->b->len > 1)
			rotate_b(i);
	}
	swap_a(i);
	while (i->b->len > 0)
		push_a(i);
}
Exemple #5
0
void			sort_pile(t_pushswap *data)
{
	while (42)
	{
		first_pile_check(data);
		put_smallest_last(data);
		if (check_pile(data->pile_a, data->length_a))
		{
			if (data->length_b == 0)
				break ;
			else if (data->length_b == 1)
				push_a(data, 1);
			else
			{
				while (data->length_b > 0)
					push_a(data, 0);
			}
		}
		else
			push_b(data, 0);
	}
}
Exemple #6
0
static void			order_b(t_push **lista, t_push **listb, t_action **actions)
{
	while (checklen(*listb) > 1 && !checkorder(*listb))
	{
		if (get_last(*listb) < get_before_last(*listb))
		{
			swap_b(lista, listb, actions);
			push_a(lista, listb, actions);
		}
		else
			break ;
	}
}
Exemple #7
0
t_action			*push_swap(t_push *lista)
{
	t_push		*listb;
	t_action	*actions;

	listb = NULL;
	actions = NULL;
	add_action(&actions, cpy_list(lista), cpy_list(listb), "START");
	order_a(&lista, &listb, &actions);
	while (checklen(listb))
	{
		push_a(&lista, &listb, &actions);
		order_a(&lista, &listb, &actions);
	}
	return (actions);
}
Exemple #8
0
void			basic_sort(t_box *box)
{
	while (box->size_a != 0)
	{
		box->locat = little_number(A, box->size_a, &box->val_min);
		if (A[0] > A[1] && A[1] < A[2])
			swap_a(box);
		if (check_sort(A, box->size_a))
			break ;
		if (box->locat < (box->size / 2))
			while (A[0] != box->val_min)
				rot_a(box);
		else
			while (A[0] != box->val_min)
				revrot_a(box);
		push_b(box);
	}
	while (box->size_b != 0)
		push_a(box);
}