Commit 854be057 authored by Marta Boshkovska's avatar Marta Boshkovska
Browse files

list chaine

parent cc6bb2ce
Loading
Loading
Loading
Loading

src/bignum.o

0 → 100644
+9.7 KiB

File added.

No diff preview for this file type.

src/bst.o

0 → 100644
+4.55 KiB

File added.

No diff preview for this file type.

src/hash_tbl.o

0 → 100644
+4.52 KiB

File added.

No diff preview for this file type.

+38 −1
Changes for src/list.c: 38 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,65 @@ struct cell_t {
typedef struct cell_t* list_t;

list_t list_empty(){
  list_t l = malloc(sizeof(list_t));
  l = NULL;
  return l;
}

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

list_t list_push(list_t l, void* x){
  list_t l1 = malloc(sizeof(list_t));
  l1->val = x;
  l1->id = l->id+1;
  l1->next = NULL;
  if(list_is_empty(l)) {
    return l1;
  }
  l1->next = l;
  return l1;
}

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

void* list_pop(list_t* l){ 
  void * v = (*l)->val;
  list_t newL = (*l)->next;
  free(*l);
  (*l) = newL;
  return v;
  }

void* list_top(list_t l){
  return l->val;
}

void list_destroy(list_t l, void (*freeVoid)(void*)){
  while(l->next != NULL) {
    freeVoid(l->val);
    free(l->next);
  }

void list_destroy(list_t l, void (*free)(void*)){
}

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

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

src/list.o

0 → 100644
+6.02 KiB

File added.

No diff preview for this file type.

Loading