forked from menault/2026_TD3_DEV51_Qualite_Algo
Merge branch 'main' of https://grond.iut-fbleau.fr/solar/2026_TD3_DEV51_Qualite_Algo
This commit is contained in:
@@ -71,18 +71,17 @@ 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 */
|
||||||
|
static int comparer_transactions(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)
|
void trier_par_montant(Transaction *t, int n)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < n - 1; i++) {
|
qsort(t, n, sizeof *t, comparer_transactions);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* F2 : nombre de clients ayant au moins une transaction */
|
/* F2 : nombre de clients ayant au moins une transaction */
|
||||||
@@ -115,11 +114,13 @@ void total_par_client(const Transaction *t, int n, long *totaux)
|
|||||||
/* F4 : solde total de chaque jour */
|
/* F4 : solde total de chaque jour */
|
||||||
void total_par_jour(const Transaction *t, int n, long *totaux)
|
void total_par_jour(const Transaction *t, int n, long *totaux)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < NB_JOURS; j++) {
|
for (int j = 0; j < NB_JOURS; j++)
|
||||||
totaux[j] = 0;
|
totaux[j] = 0;
|
||||||
for (int i = 0; i < n; i++)
|
|
||||||
if (t[i].jour == j)
|
for (int i = 0; i < n; i++) {
|
||||||
totaux[j] += t[i].montant;
|
int jour = t[i].jour;
|
||||||
|
if (jour >= 0 && jour < NB_JOURS)
|
||||||
|
totaux[jour] += t[i].montant;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user