Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.62 KB | None | 0 0
  1. void division(list l1, list l2, list *p_quotient, list *p_reste)
  2. {
  3.     list quotient_tmp = NULL;
  4.     list diviseur_tmp = NULL;
  5.     list top_l1 = l1, top_l2 = l2, top_p_reste = *p_reste;
  6.     list node = NULL;
  7.  
  8.     int i;
  9.     int lenght;
  10.    
  11.     while(top_l1){
  12.     addNewList(p_reste,top_l1->monomial);
  13.     top_l1 = top_l1->next;
  14.     }
  15.    
  16.     topl_l1 = l1;
  17.  
  18.     while(top_l1->next) top_l1 = top_l1->next;
  19.     while(top_l1->next) top_l1 = top_l1->next;
  20.  
  21.     int degree_dividende = top_l1->monomial.degree;
  22.     int degree_diviseur = top_l2->monomial.degree;
  23.     int degree_p_reste = top_l1->monomial.degree;
  24.    
  25.     if(top_l1->monomial.degree < top_l2->monomial.degree) {
  26.         printf("erreur, degré du dividende < degré du diviseur");
  27.         return;
  28.     }
  29.  
  30.     do {
  31.         quotient_tmp = (list) malloc(sizeof(listNode));
  32.         quotient_tmp->next = NULL;
  33.         quotient_tmp->monomial.degree = degree_dividende-degree_diviseur;
  34.         quotient_tmp->monomial.coef = divide(top_l1->monomial.coef,top_l2->monomial.coef);
  35.         multiply_polynomial(quotient_tmp,l2,&diviseur_tmp);
  36.  
  37.         lenght = lenght_list(*p_reste);
  38.         substraction_polynomial(*p_reste,diviseur_tmp,p_reste);
  39.  
  40.         for ( i = 0 ; i < lenght ; i++ ) {
  41.             node = *p_reste;
  42.             free(node);
  43.             node = node->next;
  44.         }
  45.        
  46.         addNewList(p_quotient,quotient_tmp->monomial);
  47.        
  48.         while(top_p_reste->next) top_p_reste = top_p_reste->next;
  49.         degree_p_reste = top_p_reste->monomial.degree;
  50.         top_p_reste = *p_reste;
  51.        
  52.         freeList(&quotient_tmp);
  53.        
  54.     } while(degree_reste >= degree_dividende);
  55.    
  56.     freeList(&diviseur_tmp);
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement