#include <iostream> using namespace std; template <class T> void trir_a_bulle(T *valeurs, int size) { register int a, b; T t; for(a=1; a < size; a++) for(b=size-1; b >= a; b--) if(valeurs[b-1] > valeurs[b]) { t = valeurs[b-1]; valeurs[b-1] = valeurs[b]; valeurs[b] = t; } } int main() { int i[] = {3, 2, 5, 6, 1, 8, 9, 3, 6, 9}; double d[] = {1.2, 5.5, 2.2, 3.3}; char c[] = {'g', 'x', 's', 'q', 'm', 'p'}; int j; trir_a_bulle(i, 10); // Trier un 'int' trir_a_bulle(d, 4); // Trier un 'double' trir_a_bulle(c, 6); // Trier un 'char' for(j=0; j<10; j++) cout << i[j] << ' '; cout << endl; for(j=0; j<4; j++) cout << d[j] << ' '; cout << endl; for(j=0; j<6; j++) cout << c[j] << ' '; cout << endl; return 0; } |
0