Compléter le code suivant :
#include <iostream>
#include <vector>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <thread>
using namespace std;
typedef vector <unsigned> CVUint;
typedef vector < vector <double>> CMatrix;
CMatrix Mat;
void SelectSort (CVUint & VUint)
{
for (unsigned i (0); i < VUint.size(); ++i)
{
CVUint::iterator Min (min_element (VUint.begin() + i, VUint.end()));
swap (VUint[i],VUint [Min - VUint.begin()]);
}
}
void InsertSort (CVUint & VUint)
{
for (unsigned i (1); i < VUint.size(); ++i)
{
unsigned Val (VUint [i]);
unsigned j (i);
for (; j > 0 && VUint[j - 1] > Val; --j)
VUint[j] = VUint[j - 1];
VUint[j] = Val;
}
}
void BubbleSort (CVUint & VUint)
{
for (unsigned i (VUint.size()); i -- > 0; )
{
bool TableauTrie = true;
for (unsigned j (0); j < i ; ++j)
{
if (VUint[j + 1] < VUint[j])
{
swap (VUint[j + 1], VUint[j]);
TableauTrie = false;
}
}
if (TableauTrie) return;
}
}
void LanguageSort (CVUint & VUint)
{
sort (VUint.begin(), VUint.end());
}
void InitMat (unsigned NbColumns)
{
Mat.resize(4, vector <double> (NbColumns));
}
void protoGenericSort(void (*Sort) (CVUint & VUint), const CVUint & VUint, unsigned NbFois, unsigned PosMat, unsigned VectNum)
{
for (unsigned i (0); i < NbFois; ++i)
{
CVUint CopyVUint (VUint);
/* TODO*/
double elapsed;
/* TODO*/
Sort (CopyVUint);
/* TODO*/
Mat [PosMat][i + NbFois * VectNum] = elapsed;
}
}
void TraiterResultats (unsigned NbElemAEnlever)
{
for (vector <double> & UneLigne : Mat)
{
//tri
sort (UneLigne.begin(), UneLigne.end());
//plus petit temps
double min (UneLigne[0]);
//plus grand temps
double max (UneLigne[UneLigne.size()-1]);
//temps median
double med (UneLigne[UneLigne.size()/2]);
//On assigne les valeurs memorisees aux 3 premières cases
UneLigne[0] = min;
UneLigne[1] = med;
UneLigne [2] = max;
}
//Affichage
cout << setw (20) << "Tri" << setw (10) << "Min" << setw (10) << "Med" << setw (10) << "Max" << endl;
vector<string> VMetode {"Selection", "Insertion", "Bulles", "Langage"};
for (unsigned i (0); i < VMetode.size(); ++i)
cout << setw (20) << VMetode[i] << setw (10) << setprecision(6) << Mat[i][0] << setw (10) << setprecision(6) << Mat[i][1] << setw (10) << setprecision(6) << Mat[i][2] << endl;
}
int main(int argc, char *argv[])
{
if (argc != 4)
{
cerr << "boulette !\n utilisation : " << argv [0] << " (1) NbElem par vecteur (2) Nb de vecteurs differents (3) Nb itérations par vecteur" << endl;
return 1;
}
unsigned NbElem (stoul(argv[1]));
unsigned NbVecteurs (stoul(argv[2]));
unsigned NbFois (stoul(argv[3]));
srand (time(NULL));
CVUint VUInt (NbElem);
InitMat(NbFois * NbVecteurs);
for (unsigned i (0); i < NbVecteurs; ++i)
{
for (auto & Val : VUInt)
Val = rand () % (VUInt.size() * 10);
thread th1 (/* TODO*/);
thread th2 (/* TODO*/);
thread th3 (/* TODO*/);
thread th4 (/* TODO*/);
th1.join();
th2.join();
th3.join();
th4.join();
cout << i << "fini" << endl;
}
cout << "Taille des vecteurs : " << NbElem << "\nNb de vecteurs : " << NbVecteurs << "\nNb iterations par vecteur : " << NbFois << endl;
TraiterResultats (NbFois * NbVecteurs / 10);
return 0;
}