This commit is contained in:
2026-10-26 15:41:53 +01:00
parent 6eb65d3903
commit 3cbbca5735
+7 -5
View File
@@ -71,7 +71,6 @@ Transaction *generer_transactions(int n)
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
/* F1 : trie les transactions par montant croissant, puis par id */ /* F1 : trie les transactions par montant croissant, puis par id */
int comparer_transactions(const void *a, const void *b)
{ {
const Transaction *t1 = a; const Transaction *t1 = a;
const Transaction *t2 = b; const Transaction *t2 = b;
@@ -91,6 +90,10 @@ int comparer_transactions(const void *a, const void *b)
return 0; return 0;
} }
void trier_par_montant(Transaction *t, int n)
{
qsort(t, n, sizeof(Transaction), comparer_transactions);
}
void trier_par_montant(Transaction *t, int n) void trier_par_montant(Transaction *t, int n)
{ {
qsort(t, n, sizeof(Transaction), comparer_transactions); qsort(t, n, sizeof(Transaction), comparer_transactions);
@@ -115,15 +118,14 @@ int nb_clients_distincts(const Transaction *t, int n)
return nb; return nb;
} }
/* F3 : solde total de chaque client */ /* F3 : solde total de chaque client */
void total_par_client(const Transaction *t, int n, long *totaux) void total_par_client(const Transaction *t, int n, long *totaux)
{ {
for (int c = 0; c < NB_CLIENTS; c++) { for (int c = 0; c < NB_CLIENTS; c++)
totaux[c] = 0; totaux[c] = 0;
for (int i = 0; i < n; i++) for (int i = 0; i < n; i++)
if (t[i].client == c) totaux[t[i].client] += t[i].montant;
totaux[c] += t[i].montant;
}
} }
/* F4 : solde total de chaque jour */ /* F4 : solde total de chaque jour */