bob82fr
Messages postés38Date d'inscriptionsamedi 1 février 2003StatutMembreDernière intervention13 janvier 2005
-
30 avril 2004 à 17:24
cs_JCDjcd
Messages postés1138Date d'inscriptionmardi 10 juin 2003StatutMembreDernière intervention25 janvier 2009
-
1 mai 2004 à 18:27
hi,
j'ai un big probleme, j'ai le code suivant:
#include "list.h"
void list_init(LIST *l, int (*cmp)())
{
l->cmp = cmp;
l->first = (LIST_NODE*)0;l->len 0; // empty list, len 0
}
static LIST_NODE * list_new_node(void *item)
{
LIST_NODE *ln;
if (!(ln = (LIST_NODE*) malloc(sizeof(LIST_NODE)))) {
printf("Unable to allocate more LIST_NODE\n");
exit(1);
}
ln->data = item;
ln->next = (LIST_NODE*)0;
return ln;
}
void *list_search(LIST * l, void *item)
{
LIST_NODE *cur;
if (!l->cmp) return 0; // if no cmp() function, never find itemfor(cur l->first; cur; cur cur->next) if ((l->cmp)(cur->data, item) == 0) return cur->data; // found
return 0;
}
// A node in the list
typedef struct list_node {
struct list_node * next; // pointer to next element in list
void * data; // pointer to data
} LIST_NODE;
// A list
typedef struct list {
LIST_NODE * first; // pointer to first node
int (*cmp)(); // pointer to comparison function (like strcmp())
int len; // number of items in the list
} LIST;
for (i=0;i<10;i++){
j = (int*)malloc(sizeof(int));
*j = i;
list_add(&aList, j);
}
a = list_len(&aList);
printf("taille=%d",a);
return 0;
}
C code a ete fais par un gas dont il faut que je reprenne le travail.
Cependant je pîge pas comment il a pu faire pour recuperer un element de ca liste...
En fait j'aimerai pouvoir recuperer la valeur d'un element de la liste en fonction de sa place.
Une sorte de getListe(position)
Generalement je fais du java et la c un peu delicat pour moi...