1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
void triInsertion (int tab[], int n)
{
int i;
int j;
int v;
for (i=2; i<n; i++)
{
v = tab[i];
j = i;
while (tab[j-1]>v)
{
tab[j-1] = tab[j];
j--;
}
tab[j] = v;
}
}
int main(int argc, char *argv[])
{
int tab[10], p;
for (p=0; p<10; p++)
tab[p] = rand();
for (p=0; p<10; p++)
printf("%d\t" ,tab[p]);
triInsertion (tab, 10);
printf("\nles elements tries sont:\n");
for (p=0; p<10; p++)
printf("%d\t",tab[p]);
system("PAUSE");
return 0;
} |
Partager