forked from abraham/2026_TD3_DEV51_Qualite_Algo
Merge pull request 'EXO 4 - optimisation F1' (#1) from framery/2026_TD3_DEV51_Qualite_Algo:main into main
Reviewed-on: abraham/2026_TD3_DEV51_Qualite_Algo#1
This commit is contained in:
@@ -73,15 +73,15 @@ 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 */
|
||||||
void trier_par_montant(Transaction *t, int n)
|
void trier_par_montant(Transaction *t, int n)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < n - 1; i++) {
|
for (int i = 1; i < n; i++) {
|
||||||
for (int j = 0; j < n - 1 - i; j++) {
|
Transaction cle = t[i];
|
||||||
if (t[j].montant > t[j + 1].montant ||
|
int j = i - 1;
|
||||||
(t[j].montant == t[j + 1].montant && t[j].id > t[j + 1].id)) {
|
while (j >= 0 && (t[j].montant > cle.montant ||
|
||||||
Transaction tmp = t[j];
|
(t[j].montant == cle.montant && t[j].id > cle.id))) {
|
||||||
t[j] = t[j + 1];
|
t[j + 1] = t[j];
|
||||||
t[j + 1] = tmp;
|
j--;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
t[j + 1] = cle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user