INFO505 Programmation C
Loading...
Searching...
No Matches
bad-tri.c
1#include <stdio.h>
2#include <stdlib.h>
3
4void echange( int* pi, int* pj )
5{
6 int t = *pi;
7 *pi = *pj;
8 *pj = t;
9}
10
11void aleatoire( int* debut, int* fin )
12{
13 for ( ; debut != fin; ++debut )
14 *debut = rand() % 100;
15}
16
17void affiche( int* debut, int* fin )
18{
19 for ( ; debut != fin; ++debut )
20 printf( " %d", *debut );
21 printf( "\n" );
22}
23
24// Tri à bulle ?
25void tri( int* debut, int* fin )
26{
27 for ( ; debut != fin-1; ++debut )
28 for ( int* bulle = fin-1; bulle != debut; ++bulle )
29 if ( *bulle < *(bulle-1) )
30 echange( bulle, bulle-1 );
31}
32
33int main()
34{
35 int t[ 20 ];
36 aleatoire( t, t+20 );
37 affiche( t, t+20 );
38 tri( t, t+20 );
39 affiche( t, t+20 );
40}