Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. tabio.h
  2.  
  3. #define LONGUEUR 10
  4.  
  5. typedef int Tableau[LONGUEUR];
  6. typedef enum { FAUX, VRAI } Booleen;
  7.  
  8.  
  9. void saisirTableau ( Tableau t ) {
  10.  
  11. int i;
  12.  
  13. for ( i=0; i<LONGUEUR; i++ ) {
  14. printf ( "t[%02d] : ", i );
  15. scanf ( "%d", &t[i] );
  16. }
  17. }
  18.  
  19. void afficherTableau ( Tableau t ) {
  20.  
  21. int i;
  22.  
  23. for ( i=0; i<LONGUEUR; i++ )
  24. printf ( "%d ", t[i] );
  25. printf ( "\n" );
  26. }
  27.  
  28.  
  29.  
  30. tabio.c
  31.  
  32. #include <stdlib.h>
  33. #include <stdio.h>
  34. #include "tabio.h"
  35.  
  36. void saisirTableau ( Tableau t );
  37. void afficherTableau ( Tableau t );
  38.  
  39.  
  40. triAbulles.c
  41.  
  42. #include <stdlib.h>
  43. #include <stdio.h>
  44. #include "tabio.h"
  45.  
  46. void echanger ( int *px, int *py ) {
  47.  
  48. int aux = *px;
  49.  
  50. *px = *py;
  51. *py = aux;
  52. }
  53.  
  54. void triAbulles ( Tableau t ) {
  55.  
  56. int i = 0, j;
  57. Booleen aucunEchange = FAUX;
  58.  
  59. while ( ( i<LONGUEUR-1 ) && !aucunEchange ) {
  60.  
  61. aucunEchange = VRAI;
  62.  
  63. for ( j=LONGUEUR-1; j>i; j-- )
  64. if ( t[j]<t[j-1] ) {
  65. echanger ( &t[j], &t[j-1] );
  66. aucunEchange = FAUX;
  67. }
  68. i++;
  69. }
  70. }
  71.  
  72. int main () {
  73.  
  74. Tableau tab;
  75.  
  76. saisirTableau ( tab );
  77. triAbulles ( tab );
  78. printf ( "Voici le tableau trie : " );
  79. afficherTableau ( tab );
  80. return EXIT_SUCCESS;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement