Commit e3deb1ac authored by Alix Danvy's avatar Alix Danvy
Browse files

bst et liste chainée

parent c0480f71
Loading
Loading
Loading
Loading
+1 −1
Changes for src/bst.c: 1 added line, 1 removed line.
Original line number Diff line number Diff line
#include <stdlib.h>

// Etienne Lehembre PROF
struct node_t {
  unsigned long int key;
  void* val;
+52 −0
Changes for src/list.c: 52 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ struct cell_t {
typedef struct cell_t* list_t;

list_t list_empty(){
<<<<<<< HEAD
    return NULL;
}

@@ -59,10 +60,49 @@ void list_destroy(list_t l, void (*free_void)(void*)){
              free(tmp);
          }
    }
=======
  return NULL;
}

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

list_t list_push(list_t l, void* x){
  list_t res = malloc(sizeof(struct cell_t));
  res->next = l;
  res->val = x;
  res->id = list_is_empty(l) ? 1 : 1 + l->id;
  return res;
}

list_t list_tail(list_t l){
  return list_is_empty(l) ? NULL : l->next;
}

void* list_pop(list_t* l){
  if(list_is_empty(*l))
    return NULL;
  list_t new_head = (*l)->next;
  void* res = (*l)->val;
  free(*l);
  *l = new_head;
  return res;
}

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

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

// return the found element or NULL
void* list_in(list_t l, void* x, int (*eq)(void*, void*)){
<<<<<<< HEAD
    while(l!=NULL) {
        if(eq(x,l->val))
            return l->val;
@@ -75,5 +115,17 @@ unsigned long int list_len(list_t l){
    if(l==NULL)
        return 0;
    return 1+l->id;
=======
  while(!list_is_empty(l))
    if(eq(x, l->val))
      return l->val;
    else
      l = l->next;
  return NULL;
}

unsigned long int list_len(list_t l){
  return list_is_empty(l) ? 0 : l->id;
>>>>>>> 84c3d114760871e56175b2e90f7c5568b89fb86d
}
+5 −5
Changes for src/list.h: 5 added lines, 5 removed lines.
Original line number Diff line number Diff line
#ifndef __LIST__
#define __LIST__

// struct cell_t {
//   void* val;
//   unsigned long int id; // size
//   struct cell_t* next;
// };
struct cell_t {
  void* val;
  unsigned long int id; // size
  struct cell_t* next;
};

typedef struct cell_t* list_t;