détermination des indices initiaux d'un tableau après tri
Bonjour,
Le programme en c ci-dessous permet de trier les éléments d'un tableau t par ordre croissant.
Code:
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 37 38 39
|
#include <stdio.h>
#include <stdlib.h>
void selection(int *t, int n)
{
int i, min, j , x;
for(i = 0 ; i < n-1 ; i++)
{
min = i;
for(j = i+1 ; j < n ; j++)
if(t[j] < t[min])
min = j;
if(min != i)
{
x = t[i];
t[i] = t[min];
t[min] = x;
}
}
}
int main()
{
int k, min;
int t[6]={3,6,9,10,1,2};
selection(t, 6);
for(k=0;k<6;k++)
{
printf("%d",t[k]);
}
return 0;
} |
Mon souci ce que je voudrais récupérer les indices initiales des nombres du tableau trié.
exemple :
tableau non trié : 3 6 9 10 1 2
tableau trié : 1 2 3 6 9 10
indice : 4 5 0 1 2 3
Je n'arrive pas à le faire. Un coup de pouce pourra m'aider!
Merci