Tri d’un tableau

Nanafa -  
 cest_pas_faux -
Bonjour,
Je suis un étudiant,j'ai besoin de faire un programme de trier un tableau par sélection en langage c.Qelqu'un peut m'aider stp.

Configuration: iPhone / Safari 10.0

2 réponses

  1. TheKill_TnT Messages postés 172 Statut Membre 40
     
    Tu peux reformuler ? Plus d'explications s'il te plaît.
    0
  2. cest_pas_faux
     

    #include <stdio.h>

    int *exchange(int *tab, int a, int b)
    {
    int temp = 0;
    temp = tab[a];
    tab[a] = tab[b];
    tab[b] = temp;
    return tab;
    }

    void print(int *tab, int size)
    {
    for (int i = 0; i < size; i++)
    {
    printf("%d ", tab[i]);
    }
    printf("\n");
    }

    int *selection(int *tab, int size)
    {
    int min = 0;
    for (int i = 0; i < size - 1; i++)
    {
    for (int j = i; j < size; j++)
    {
    if (tab[j] < tab[min])
    {
    min = j;
    }
    }
    tab = exchange(tab, i, min);
    min = i + 1;
    }
    return tab;
    }

    int main()
    {
    int t[] = {6, 2, 3, 1, 5, 4};

    int size = sizeof t / sizeof (int);
    int *tab = selection(t, size);
    print(tab, size);

    return 0;
    }
    0