EXO 4 - optimisation F1

This commit is contained in:
2026-10-21 11:17:43 +02:00
parent 1f17823a2c
commit a5e748e993
+8 -8
View File
@@ -73,15 +73,15 @@ Transaction *generer_transactions(int n)
/* F1 : trie les transactions par montant croissant, puis par 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;
}
for (int i = 1; i < n; i++) {
Transaction cle = t[i];
int j = i - 1;
while (j >= 0 && (t[j].montant > cle.montant ||
(t[j].montant == cle.montant && t[j].id > cle.id))) {
t[j + 1] = t[j];
j--;
}
t[j + 1] = cle;
}
}