//Program TriBulles
/* Trier un tableau à 2 dimensions par la méthode de tri bulle*/
#include<iostream>
using namespace std;
const short max=10;
typedef short table[max];
void saisirTab(table tab,short taille);
void afficherTab(table tab,short taille);
void echanger2E(short&nb1,short&nb2);
void trieBulles(table tabEnt,short taille);
void main()
{
table tab;
short taille;
do {cout<<"Nombre d'elements du tableau (2 a "<<max<<")?";
cin>>taille;
}while((taille<2)||(taille>max));
saisirTab(tab,taille); cout<<endl;
trieBulles(tab,taille);
cout<<"Tableau trie :" ;afficherTab(tab,taille);
cout<<endl<<endl;
}
void trieBulles(table tabEnt,short taille)
/* Trier en ordre croissant un tableau à 1 dimension par la méthode de tri bulle*/
{bool permut;
do
{permut=false;
for(short i=0;i<taille-1;i++)
{if(tabEnt[i]>tabEnt[i+1])
{echanger2E(tabEnt[i],tabEnt[i+1]);permut=true;}
}
}while (permut==true);
}/*Fin trieBulle*/
void saisirTab(table tabEnt,short taille)
//Saisit les elements d'un tableau a 1 dimension
{
for(short i=0;i<taille;i++)
{cout<<"Entrer l'element "<<i+1<<" du tableau : "; cin>>tabEnt[i];}
}/*Fin saisirTab*/
void afficherTab(table tabEnt,short taille)
//Affiche les elements d'un tableau a 1 dimension
{
for(short i=0;i<taille;i++) cout<<tabEnt[i]<<" ";
}/*Fin afficherTab*/
void echanger2E(short&nb1,short&nb2)
//Echanger les valeurs de 2 entiers
{
short tampon=nb1;nb1=nb2;nb2=tampon;
}/*Fin echanger2E*/