/*-----------------------------------------------------------/ Le code ci-dessous est l’implémentation d’un Tri Bulle Itératif avec Drapeau. Pour une bonne lisibilité, nous avons écrit trois fonctions à savoir la Fonction d’Echange, le Tri proprement dit et pour finir une fonction d’affichage des éléments. /------------------------------------------------------------*/ #include using namespace std; void Ecgange(int *, int , int ); void Tri_Bulle_IteratifD(int *, int , int ); void Afficher(int *, int, int ); //Fonction principale int main() { int Tab[] = {10,2,6,30,40,7}; cout << "\nValeur du tableau nom trie : \n"; Afficher(Tab, 0, 6); Tri_Bulle_IteratifD(Tab, 0, 6); cout << "\nValeur du tableau trie : \n"; Afficher(Tab, 0, 6); return 0; } //Fonction Echage void Echange(int *Tab, int i, int j) { int temp; //variable temporaire pour faciliter la permutation temp = Tab[i]; Tab[i] = Tab[j]; Tab[j] = temp; } //Fonction du tri Bulle Iteratif void Tri_Bulle_IteratifD(int *Tab, int H, int B) { int i, j = H; bool Drapeau ; do { Drapeau = false; for(i=B; i>= H+j; i--) { if(Tab[i] < Tab[i-1]) { Echange(Tab, i, i-1); Drapeau = true; } } j++; } while((j < B-H) || (Drapeau = false)); //while((j > B-1) || (Drapeau = false)); } //Fonction d'affichage des elements du tableau void Afficher(int *Tab, int H, int B) { int i; for(i= H; i< B; i++) cout << Tab[i] <<" | "; cout<< endl; }