TP5 Questions supplémentaires
This commit is contained in:
parent
46b1ecc22c
commit
1e9f628d4c
|
@ -87,7 +87,7 @@ void details(Cellule *l, char nom) {
|
|||
printf("\nListe %c :\n", nom);
|
||||
imprimer(l);
|
||||
if (est_trie(l)) {
|
||||
printf("→ Est trié\n");
|
||||
printf("→ Est triée\n");
|
||||
} else {
|
||||
printf("→ N'est pas triée\n");
|
||||
}
|
||||
|
@ -101,9 +101,7 @@ Cellule* union_me(Cellule* j, Cellule* k) {
|
|||
return NULL;
|
||||
} else {
|
||||
u = union_me(NULL, k->suiv);
|
||||
for (i = 0; i < k->mult; i++) {
|
||||
inserer(&u, k->val);
|
||||
}
|
||||
ajout_tete(&u, k->val, k->mult);
|
||||
return u;
|
||||
}
|
||||
} else {
|
||||
|
@ -129,7 +127,7 @@ Cellule* intersection_me(Cellule* j, Cellule* k) {
|
|||
} else if (j->val == k->val) {
|
||||
Cellule* i;
|
||||
i = intersection_me(j->suiv, k->suiv);
|
||||
inserer(&i, min(j->val, k->val));
|
||||
ajout_tete(&i, j->val, min(j->mult, k->mult));
|
||||
return i;
|
||||
} else if (j->val < k->val) {
|
||||
return intersection_me(j->suiv, k);
|
||||
|
@ -138,6 +136,29 @@ Cellule* intersection_me(Cellule* j, Cellule* k) {
|
|||
}
|
||||
}
|
||||
|
||||
Cellule* difference_me(Cellule* j, Cellule* k) {
|
||||
Cellule* i;
|
||||
if (k == NULL && j == NULL) {
|
||||
i = NULL;
|
||||
} else if (j == NULL) {
|
||||
i = difference_me(NULL, k->suiv);
|
||||
ajout_tete(&i, k->val, - k->mult);
|
||||
} else if (k == NULL) {
|
||||
i = difference_me(j->suiv, NULL);
|
||||
ajout_tete(&i, j->val, j->mult);
|
||||
} else if (j->val == k->val) {
|
||||
i = difference_me(j->suiv, k->suiv);
|
||||
ajout_tete(&i, j->val, j->mult - k->mult);
|
||||
} else if (j->val < k->val) {
|
||||
i = difference_me(j->suiv, k);
|
||||
ajout_tete(&i, j->val, j->mult);
|
||||
} else {
|
||||
i = difference_me(j, k->suiv);
|
||||
ajout_tete(&i, k->val, - k->mult);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
Cellule* j = NULL;
|
||||
|
@ -164,5 +185,7 @@ int main() {
|
|||
Cellule* i = intersection_me(j, k);
|
||||
details(i, 'i');
|
||||
|
||||
Cellule* d = difference_me(j, k);
|
||||
details(d, 'd');
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue