Algo,tri

Bonjour,
pouvez vous m'aidez à faire un algorithme de tri par selection
Configuration: Windows XP
Internet Explorer 7.0

5 réponses

  1. bonjours
    ici dans ce programme il y a deux tris par selection et par bull
    pour activer bull il sufi tout simplement mettre les // dans bull et les supprimer dans selection
    #include<stdio.h>
    #include<conio.h>
    void permuter(int*,int*);
    //void tri_bull_tp(int*,int );
    void tri_selection(int*,int);
    main()
    { int i,n,t[20];
    printf("entrer la taille du tableau");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {printf("t[%d]=",i);
    scanf("%d",&t[i]);}

    //tri_bull_tp(t,n);
    tri_selection(t,n);

    for(i=0;i<n;i++)
    printf("%d\n",t[i]);

    getch();}

    void permuter(int*a,int*b)
    { int c;
    c=*a;
    *a=*b;
    *b=c;
    }
    void tri_bull_tp(int t[],int n)

    {int m,c,i;
    do{m=0;
    for(i=0;i<n;i++)
    if(t[i]>t[i+1])
    { permuter(&t[i],&t[i+1]); m=1;}
    }while(m==1);}
    void tri_selection(int t[],int n)
    {int i,j;
    for(i=0;i<n-1;i++)
    for(j=i+1;j<n;j++)
    if(t[i]>t[j])
    {permuter(&t[i],&t[j]);}

    }
    0
    1. salut c'est asma je te propose cette solution
      procedure permutation(var x:entier,var y:entier)
      var
      h:entier
      debut
      h<- x
      x<- y
      y<- h
      fin

      fonctin recherche pos-min(T:tableau[1..n],p:entier):entier
      var
      i,min,pos:entier
      debut
      min<- T[p]
      pour i de p+1 pas -1 à n faire
      si(T[i]<min) alors
      min<- T[i]
      pos<- i
      fin si
      fin pour
      pos<- recherche pos-min
      fin

      procedure tri selection(var T:tableau[1..n]d'entier,n:entier)
      var
      i,pmin:entier
      debut
      pour i de 1 à n faire
      pmin<- recherche pos-min(T,n,i)
      si(pmin<>i) alors
      permutation(T[i],T[pmin])
      fin si
      fin pour
      fin
      1
      1. essaye ce lien
        http://www.dailly.info/algorithmes-de-tri/selection.php
        tu trouvra le code soure de tri par selection
        0