Besoin d'idée pour le tri d'une liste de client
Bonsoir, mon problème est que j'ai une liste ( pas de la library liste.h ) de client ( une class client ) et je dois performer des tri croissant ou décroissant selon l'id du client ou son nombre d'achat.
Voici ma fonction de tri de ma classe liste
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
| void Trier(string option)
{
if (_compte > 1)
{
NoeudPtr pivot = _tete;
NoeudPtr courant;
NoeudPtr reserve;
while (pivot->suivant != _tete)
{
courant = pivot->suivant;
reserve = pivot;
while (courant != _tete)
{
if(option == "croissant")
{
if (*reserve->objetPtr > *courant->objetPtr)
reserve = courant;
}
if(option == "desc")
{
if (*reserve->objetPtr < *courant->objetPtr)
reserve = courant;
}
courant = courant->suivant;
}
if (reserve!=pivot)
{
Objet* objetPtr = reserve->objetPtr;
reserve->objetPtr = pivot->objetPtr;
pivot->objetPtr = objetPtr;
}
pivot = pivot->suivant;
}
}
} |
ma fonction tri marche très bien pour l'id du client mais je ne peux pas le faire pour le total d'achat car dans ma class client les opérateurs '<' et '>' son déja surchargé pour retourné le plus grand/petit id du client.
Je ne sais pas si vous comprenez se que je veux dire ...
Code:
1 2 3 4 5 6 7 8 9
| friend bool operator>(const Clients& client1,const Clients& client2)
{
return ( client1.GetIdClient() > client2.GetIdClient() );
}
friend bool operator<(const Clients& client1, const Clients& client2)
{
return ( client1.GetIdClient() < client2.GetIdClient() );
} |