Previous Next Up Index Contents

Exercice 10.19 Tri par sélection

#include <stdio.h>

main()
{
 /* Prototypes des fonctions appelées */
 void TRI_SELECTION(int *T, int N);
 void LIRE_TAB (int *TAB, int *N, int NMAX);
 void ECRIRE_TAB (int *TAB, int N);
 /* Variables locales */
 int T[100]; /* Tableau d'entiers */
 int DIM;    /* Dimension du tableau */ 


/* Traitements */
 LIRE_TAB (T, &DIM, 100);
 printf("Tableau donné : \n");
 ECRIRE_TAB (T, DIM);
 TRI_SELECTION(T, DIM);
  printf("Tableau trié : \n");
 ECRIRE_TAB (T, DIM);
 return 0;
}

void TRI_SELECTION(int *T, int N)
{
  /* Prototypes des fonctions appelées */
 void PERMUTER(int *A, int *B);
 int *MAX3(int *TAB, int N);
 /* Variables locales */
 int I;  /* rang à partir duquel T n'est pas trié */

 /* Tri par sélection directe du maximum */
 for (I=0 ; I<N-1 ; I++)
      PERMUTER(T+I, MAX3(T+I,N-I) );
}
 
int *MAX3(int *TAB, int N)
{
 . . .
}

void PERMUTER(int *A, int *B)
{
 . . .
}

void LIRE_TAB (int *TAB, int *N, int NMAX)
{
 . . .
}

void ECRIRE_TAB (int *TAB, int N)
{
 . . .
}


Previous Next Up Index Contents

Feedback - Copyright © 1993,1996,1997 F.Faber