Commit fc591658 authored by Romain Andres's avatar Romain Andres
Browse files

corrections apportées sur les listes chainées

parent fb2d3458
Loading
Loading
Loading
Loading
+19 −4
Changes for src/list.c: 19 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -19,6 +19,11 @@ int list_is_empty(list_t l) {
list_t list_push(list_t l, void* x) {
  list_t newCase = malloc(sizeof(struct cell_t));
  newCase->val = x;
  newCase->id = 1;
  newCase->next = NULL;
  if(list_is_empty(l)) {
    return newCase;
  }
  newCase->id = l->id+1;
  newCase->next = l;
  return newCase;
@@ -65,8 +70,8 @@ void* list_top(list_t l) {
//free_void permet de dealouer val 
void list_destroy(list_t l, void (*free_void)(void*)) {
  list_t currentCase;
  while(l->next != NULL) {
    currentCase = l->next;
  while(l != NULL) {
    currentCase = list_tail(l);
    free_void(l->val);
    free(l);
    l = currentCase;
@@ -75,10 +80,20 @@ void list_destroy(list_t l, void (*free_void)(void*)) {

// return the found element or NULL
void* list_in(list_t l, void* x, int (*eq)(void*, void*)) {

  if (list_empty(l)) {
    return NULL;
  }
  list_t tmp = l;
  while( tmp != NULL) {
    if(eq(tmp->val,x)) {
      return tmp->val;
    }
    tmp = list_tail(tmp);
  }
  return NULL;
}

unsigned long int list_len(list_t l) {
  
  return l->id;
}
+312 B (8.66 KiB)

File changed.

No diff preview for this file type.

+4.05 KiB (33.3 KiB)

File changed.

No diff preview for this file type.

+29.4 KiB

File added.

No diff preview for this file type.

+64 B (34.4 KiB)

File changed.

No diff preview for this file type.