Example #1
0
char	*inf_div(char *st1, char *st2, char *base)
{
  t_div	*ptr;
  char	n;
  char	*resultat;
  char	a;

  ptr = init_struct_div(st1, st2, base, ptr);
  a = n = ptr->i = 0;
  resultat = (char *) malloc_resultat(resultat, ptr->nb1, ptr->nb2);
  ptr->tmp = (char *) my_strdivcpy(ptr->nb1, my_strlen(ptr->nb2), ptr->i, a);
  while (is_bigger(ptr->tmp, ptr->nb2, ptr->base) == 0)
    {
      a = a + 1;
      ptr->tmp = (char *) my_strdivcpy(ptr->nb1, 
				       my_strlen(ptr->nb2), ptr->i, a);
    }
  while (my_strdivcmp(ptr->tmp, ptr->nb2) >= 0 
	 && ptr->nb1[ptr->i + my_strlen(ptr->nb2) - 1] != '\0' 
	 || is_bigger(ptr->tmp, ptr->nb2, ptr->base) > 0)
    {
      n = n + 1;
      ptr->tmp = (char *) inf_sous(ptr->tmp, ptr->nb2, ptr->base);
      resultat = calc_one(ptr, a, &n, resultat);
      resultat = calc_two(ptr, a, resultat, n);
    }
  return (resultat);
}
Example #2
0
void	rempile(t_shell *head)
{
	if (l_nb(head->sa) > head->sa->nb)
		ft_rra(head, 1);
	while (l_len(head->sb) > 1)
	{
		if (l_len(head->sb) > 2 && head->sb->nb > head->sb->n->nb &&
head->sb->nb > head->sb->n->n->nb)
			rb_or_rr(head);
		while (is_bigger(head->sa, head->sb->nb, head->min))
			while_bigger(head);
		ft_pa(head, 1);
		if (head->sa->nb > head->sa->n->nb && head->sa->n->nb != head->min)
		{
			if (l_len(head->sb) > 1 && head->sb->nb > head->sb->n->nb)
				ft_ss(head, 1);
			else
				ft_sa(head, 1);
		}
		while (is_smallest(head->sb, head->sa->nb) && !ft_sorted(head->sa))
			while_smallest(head);
	}
	ft_pa(head, 1);
	if (head->sa->nb > head->sa->n->nb && head->sa->n->nb != head->min)
		ft_sa(head, 1);
	ft_ra(head, 1);
}
int* sub(int* a,int* b,int size_a,int size_b,bool sign_a,bool sign_b,bool &sign_result,int &size_result)
{
	int* res;
	if(sign_a == sign_b)
	{
		size_result=size_a+1;
		if(size_a<size_b)
		{
			size_result=size_b+1;
		}

		res = (int*) malloc((size_result + 2)*sizeof(int));
	
		int* a1 = (int*) malloc((size_result + 2)*sizeof(int));
		int* b1 = (int*) malloc((size_result + 2)*sizeof(int));
		for(int i=0;i<size_result;++i)
			res[i]=0;
		for(int i=0;i<size_result;++i)
			b1[i]=0;
		for(int i=0;i<size_result;++i)
			a1[i]=0;
		for(int i=0;i<size_b;++i)
			b1[i]=b[i];
		for(int i=0;i<size_a;++i)
			a1[i]=a[i];

		sign_result=sign_a;
		if(is_bigger(b,size_b,a,size_a))
		{
			int* buff=b1;
			b1=a1;
			a1=buff;
			int buf=size_b;
			size_b=size_a;
			size_a=buf;
			sign_result=!sign_result;
		}
		for(int i=0;i<size_result;++i)
		{
			res[i]+=a1[i]-b1[i];
			if(res[i]<0 && i<size_result-1)
			{
				res[i]+=10;
				res[i+1]-=1;
			}
		}
		free(a1);
		free(b1);
	}
	else if(sign_a)
		res = summ(a,b,size_a,size_b,1,1,sign_result,size_result);
	else
		res = summ(a,b,size_a,size_b,0,0,sign_result,size_result);
	while (res[size_result-1] == 0)
		size_result-- ;
	
	return res;

}
Example #4
0
char	*calc_one(t_div *ptr, char a, char *n, char *resultat)
{
  if (my_strdivcmp(ptr->tmp, ptr->nb2) < 0 
      && is_bigger(ptr->tmp, ptr->nb2, ptr->base) == 0)
    {
      resultat[ptr->i] = ptr->base[*n];
      ptr->nb1 = (char *) my_strdivcpy2(ptr->nb1, ptr->tmp);
      ptr->i++;
      ptr->tmp = (char *) my_strdivcpy(ptr->nb1, my_strlen(ptr->nb2), 
				       ptr->i, a);
      (*n) = 0;
    }
  return (resultat);
}
Example #5
0
void Disjoint_set::set_union(int a, int b)
{
	// calculate new size
	int a_root = find(a);
	int b_root = find(b);
	int new_size = array[a_root]+array[b_root];

	// union the tree with smaller size into the tree with bigger size
	if( is_bigger(a_root, b_root) )
	{
		array[b_root] = a_root;
		array[a_root] = new_size;
	}
	else
	{
		array[a_root] = b_root;
		array[b_root] = new_size;
	}
}
int* div(int* a,int* b,int size_a,int size_b,bool sign_a,bool sign_b,bool &sign_result,int &size_result,bool act)
{
	int* res;
	if(is_bigger(b,size_b,a,size_a))
	{
		if(!act)
		{
			size_result=1;
			res=(int*) malloc((size_result + 2)*sizeof(int));
			res[0]=0;
			res[1]=0;
			return res;
		}
		else
			{
			if(sign_a && sign_b)
				sign_result=1;
			if(!sign_a && sign_b)
				sign_result=0;
			size_result=size_a;
			res=(int*) malloc((size_result + 2)*sizeof(int));
			for(int i=0;i<size_result;++i)
				res[i]=a[i];
			return res;
		}
	}
	reverse_num(a,size_a);
	int size_q=size_a;
	int* q=(int*) malloc((size_q + 2)*sizeof(int));
	int size_cur=0;
	int* cur=(int*) malloc((size_q + 2)*sizeof(int));
	int size_r=size_b;
	for(int i=0;i<size_a;++i)
	{
		q[i]=0;
		cur[i]=0;
	}
	if(sign_a && sign_b)
		sign_result=0;
	else
		sign_result= sign_a || sign_b;
	int iq=0;
	for(int i=0;i<size_a;++i)
	{
		cur[size_cur]=a[i];
		
		++size_cur;
		
		reverse_num(cur,size_cur);
		if(is_bigger(b,size_b,cur,size_cur))
		{
			iq++;
			reverse_num(cur,size_cur);
			continue;
		}
		bool sign=0;
		
		while((is_bigger(cur,size_cur,b,size_b) || is_equal(cur,size_cur,b,size_b)) && !sign)
		{
			++q[iq];
			int aaa=size_cur;
			
			int* new_cur=sub(cur,b,aaa,size_b,0,0,sign,size_cur);
			free(cur);
			cur=new_cur;
			

		}
		++iq;
		reverse_num(cur,size_cur);
		
	}
	size_q=iq;
	reverse_num(cur,size_cur);	
	reverse_num(q,size_q);
	while (q[size_q-1] == 0)
		size_q-- ;
	while (cur[size_cur-1] == 0)
		size_cur-- ;
	if(act)
	{
		if(sign_a && sign_b)
				sign_result=1;
		if(!sign_a && sign_b)
				sign_result=0;
		free(q);
		res=cur;
		size_result=size_cur;
	}
	else
	{
		free(cur);
		res=q;
		size_result=size_q;
	}
  return res;
}