magdani  | Tu as raison
 En fait, j'ai oublié de retirer la routine de tri, une fois les numéros triés, on a perdu le lien avec les indices.
   Mes résultats sont sont de même faux.
   int numero[5];   En supposant que numero  ait ces valeurs = 10, 40, 2, 60 ,4
 int ind[5]; // indice     Le résultat dans un ListBox donnera :
 for (int i = 0; i < 5; i++)
 { ind[i] = i;
 ListBox1->Items->Add(IntToStr(numero[i]) + " " +IntToStr(ind)); }
   10    0
 40    1   2     2
 60   3
 4     4
   J'aimerais le résultat suivant
  for (int i = 0; i < 5; i++)
 ListBox1->Items->Add(IntToStr(numero[i]) + " " +IntToStr(ind));
 2      0
 4      1
 10    2   40    3
 60    4    
  Code :
 - //---------------------------------------------------------------------------
 - #include <vcl.h>
 - #pragma hdrstop
 - #include "Unit2.h"
 - #include <iostream>
 - #include <algorithm>    // std::sort
 - #include <array>
 - #include <numeric>
 - #include <vector>
 - //---------------------------------------------------------------------------
 - #pragma package(smart_init)
 - #pragma resource "*.dfm"
 - TForm2 *Form2;
 -  using namespace std;
 - // ****** solution 1
 -   struct MyStruct
 -   {
 - 	int index;
 - 	int value;
 -   };
 -  std::vector<MyStruct> datas;
 - void sortByValue(std::vector<MyStruct> & tab){
 - 	std::sort(tab.begin(), tab.end(), [&](MyStruct const & a, MyStruct const & b){return a.value < b.value;});
 - }
 - void sortById(std::vector<MyStruct> & tab){
 - 	std::sort(tab.begin(), tab.end(), [&](MyStruct const & a, MyStruct const & b){return a.index< b.index;});
 - }
 -  // ****** solution 2
 - std::array<int,5> numero={10,40,2,60,4};
 - std::array<int,5>  ind;
 - //---------------------------------------------------------------------------
 - __fastcall TForm2::TForm2(TComponent* Owner)
 - 	: TForm(Owner)
 - {
 - }
 - //---------------------------------------------------------------------------
 - void __fastcall TForm2::Button1Click(TObject *Sender)
 - {
 - //*** solution 1
 -  int numero[5];
 - 
 -  for (int i = 0; i < 5; i++)
 - {
 -  numero[0] = 10;
 -  numero[1] = 40;
 -  numero[2] = 2;
 -  numero[3] = 60;
 -  numero[4] = 4;
 - }
 - 
 - 	for(int i=0;i<5;++i) datas.push_back({i, numero[i]});
 - 
 -   sortByValue(datas); // Tri par valeur
 - 
 -  ListBox1->Items->Add("*** Solution 1" );
 -  ListBox1->Items->Add("Tri par valeur" );
 -   for(auto const & d : datas){ListBox1->Items->Add(IntToStr(d.value) +"  " + IntToStr(d.index));
 -   }
 - 
 - 
 -   sortById(datas); // Tri par index
 - 
 -   ListBox1->Items->Add("Tri par index" );
 - 
 -   for(auto const & d : datas){ListBox1->Items->Add(IntToStr(d.value) +"  " +IntToStr(d.index));
 -   }
 - 
 - }
 - 
 - //---------------------------------------------------------------------------
 - 
 - 
 - 
 - void __fastcall TForm2::Button2Click(TObject *Sender)
 - {
 - //*** solution 2
 - 
 -  ListBox2->Items->Add("*** Solution 2" );
 -  struct {
 -   bool operator()(int a, int b) const
 -   {
 -   	return numero[a] < numero[b];
 -   }
 - 	} customLess;
 - 
 -  std::iota(ind.begin(), ind.end(), 0 );  // reçoit 0 1 2 3 4
 -  std::sort(ind.begin() , ind.end() , customLess);
 -  for(int i=0;i<5;i++)
 - 	ListBox2->Items->Add(IntToStr(numero[i]) + " " +IntToStr(ind[i]));
 - }
 - //---------------------------------------------------------------------------
 
  |  
 
     |