OVH Cloud OVH Cloud

qsort avec un tableau de structure HELP !!!

2 réponses
Avatar
David Roman
typedef struct {
uint Key;
int Nb;
uint *List;
} ListTri;

int fcmp(const void * Elt1,const void * Elt2)
{
MON PROBLEME EST LA !!!

comment manipuler les structures Elt1 et Elt2 ?????

}

int main (void)
{
ListTri **Ti_Se;


Ti_Se=malloc(10*sizeof(ListTri *));
...
...
...
...
...

qsort(Ti_Se,10,sizeof(ListTri),fcmp); <= L'APPEL EST IL CORRECT
}

2 réponses

Avatar
Laurent Wacrenier
David Roman écrit:
typedef struct {
uint Key;
int Nb;
uint *List;
} ListTri;

int fcmp(const void * Elt1,const void * Elt2)
{
MON PROBLEME EST LA !!!

comment manipuler les structures Elt1 et Elt2 ?????


Par exemple :

struct ListTri l1 = Elt1, l2 = Elt2;
return l1->Key - l2->Key;

}


Avatar
Pascal Bourguignon
Laurent Wacrenier <lwa@ teaser . fr> writes:

David Roman écrit:
typedef struct {
uint Key;
int Nb;
uint *List;
} ListTri;

int fcmp(const void * Elt1,const void * Elt2)
{
MON PROBLEME EST LA !!!

comment manipuler les structures Elt1 et Elt2 ?????


Par exemple :

struct ListTri l1 = Elt1, l2 = Elt2;


struct ListTri* l1 = Elt1;
struct ListTri* l2 = Elt2;

return l1->Key - l2->Key;

}



--
__Pascal_Bourguignon__
http://www.informatimago.com/
Do not adjust your mind, there is a fault in reality.