F1 POUR L4INSTANT

This commit is contained in:
youness
2026-10-21 12:28:17 +02:00
parent e337ed5236
commit 8f4876e514
7 changed files with 6247 additions and 11 deletions
+10 -11
View File
@@ -71,19 +71,18 @@ Transaction *generer_transactions(int n)
/* ------------------------------------------------------------------ */
/* F1 : trie les transactions par montant croissant, puis par id */
static int cmp_montant_id(const void *a, const void *b)
{
const Transaction *x = a, *y = b;
if (x->montant != y->montant)
return (x->montant > y->montant) - (x->montant < y->montant);
return (x->id > y->id) - (x->id < y->id);
}
void trier_par_montant(Transaction *t, int n)
{
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - 1 - i; j++) {
if (t[j].montant > t[j + 1].montant ||
(t[j].montant == t[j + 1].montant && t[j].id > t[j + 1].id)) {
Transaction tmp = t[j];
t[j] = t[j + 1];
t[j + 1] = tmp;
}
}
}
}
qsort(t, n, sizeof(Transaction), cmp_montant_id);
}
/* F2 : nombre de clients ayant au moins une transaction */
int nb_clients_distincts(const Transaction *t, int n)