Commit e04d780e authored by Gary Neveu's avatar Gary Neveu
Browse files

fin du tp

parent 6fcaad20
Loading
Loading
Loading
Loading

src/bignum.o

0 → 100644
+9.66 KiB

File added.

No diff preview for this file type.

src/bst.o

0 → 100644
+4.51 KiB

File added.

No diff preview for this file type.

src/hash_tbl.o

0 → 100644
+4.49 KiB

File added.

No diff preview for this file type.

+44 −1
Changes for src/list.c: 44 added lines, 1 removed line.
Original line number Diff line number Diff line
#include <stdlib.h>

struct cell_t {
  void* val;
  unsigned long int id;
@@ -7,30 +9,71 @@ struct cell_t {
typedef struct cell_t* list_t;

list_t list_empty(){
  struct cell_t * liste = NULL;
  return(liste);
}

int list_is_empty(list_t l){
  return(l == NULL);
}

list_t list_push(list_t l, void* x){
  list_t newCell = malloc(sizeof(struct cell_t));
  newCell -> next = l;
  newCell -> val = x;

  if(list_is_empty(l)){
    newCell -> id = 1;
  }else{
    newCell -> id = l -> id + 1;
  }

  return(newCell);
}

list_t list_tail(list_t l){
  return(l -> next);
}

void* list_pop(list_t* l){
  if(list_is_empty(*l)){
    return NULL;
  }

  void* res = (*l) -> val;
  list_t newHead = (*l) -> next;
  free(*l);
  *l = newHead;

  return(res);
}

void* list_top(list_t l){
  if(list_is_empty(l)){
    return(NULL);
  }else{
    return(l -> val);
  }
}

void list_destroy(list_t l, void (*free)(void*)){
  while(!list_is_empty(l)){
    free(list_pop(&l));
  }
}

// return the found element or NULL
void* list_in(list_t l, void* x, int (*eq)(void*, void*)){
  while(l != NULL){
    if(eq(l -> val, x)){
      return l -> val;
    }else{
      l = l -> next;
    }
  }
  return NULL;
}

unsigned long int list_len(list_t l){
  return(l -> id);
}

src/list.o

0 → 100644
+6.12 KiB

File added.

No diff preview for this file type.

Loading