Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tabio.h
- #define LONGUEUR 10
- typedef int Tableau[LONGUEUR];
- typedef enum { FAUX, VRAI } Booleen;
- void saisirTableau ( Tableau t ) {
- int i;
- for ( i=0; i<LONGUEUR; i++ ) {
- printf ( "t[%02d] : ", i );
- scanf ( "%d", &t[i] );
- }
- }
- void afficherTableau ( Tableau t ) {
- int i;
- for ( i=0; i<LONGUEUR; i++ )
- printf ( "%d ", t[i] );
- printf ( "\n" );
- }
- tabio.c
- #include <stdlib.h>
- #include <stdio.h>
- #include "tabio.h"
- void saisirTableau ( Tableau t );
- void afficherTableau ( Tableau t );
- triAbulles.c
- #include <stdlib.h>
- #include <stdio.h>
- #include "tabio.h"
- void echanger ( int *px, int *py ) {
- int aux = *px;
- *px = *py;
- *py = aux;
- }
- void triAbulles ( Tableau t ) {
- int i = 0, j;
- Booleen aucunEchange = FAUX;
- while ( ( i<LONGUEUR-1 ) && !aucunEchange ) {
- aucunEchange = VRAI;
- for ( j=LONGUEUR-1; j>i; j-- )
- if ( t[j]<t[j-1] ) {
- echanger ( &t[j], &t[j-1] );
- aucunEchange = FAUX;
- }
- i++;
- }
- }
- int main () {
- Tableau tab;
- saisirTableau ( tab );
- triAbulles ( tab );
- printf ( "Voici le tableau trie : " );
- afficherTableau ( tab );
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement