1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include <iostream>
using std::cout;
using std::endl;
#include <iomanip>
using std::setw;
void triBulle( int *, const int );
int main()
{
const int tailleTableau = 10;
int a[ tailleTableau ] = { 2, 6, 4, 8, 10, 12, 89, 68, 45, 37 };
int i;
cout << "Elements de donnees dans l'ordre initial\n";
for ( i = 0; i < tailleTableau; i++ )
cout << setw ( 4 ) << a[ i ];
triBulle( a, tailleTableau );
cout << "\n Elements de donnees en ordre ascendant\n";
for ( i = 0; i < tailleTableau; i++ )
cout << setw ( 4 ) << a[ i ];
cout << endl;
system("PAUSE");
return 0;
}
void triBulle( int *tableau, const int taille )
{
void permutation( int * const, int * const );
for ( int passage = 0; passage < taille - 1; passage++ )
for ( int j = 0; j < taille - 1; j++ )
if ( tableau [ j ] > tableau[ j + 1 ] )
permutation( &tableau [ j ], &tableau[ j ] );
}
void permutation( int * const element1Ptr, int * const element2Ptr )
{
int maintien = *element1Ptr;
*element1Ptr = *element2Ptr;
*element2Ptr = maintien;
} |
Partager