forked from menault/2026_TD3_DEV51_Qualite_Algo
opti n1
This commit is contained in:
@@ -71,18 +71,29 @@ 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 *t2 = b;
|
||||||
|
|
||||||
|
if (t1->montant < t2->montant)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (t1->montant > t2->montant)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (t1->id < t2->id)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (t1->id > t2->id)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
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(Transaction), 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 */
|
||||||
|
|||||||
Reference in New Issue
Block a user