diff --git a/src/bignum.c b/src/bignum.c index e1386ee65d8d398991a3c8337fce38c6a67c03b1..12c47bbbd70faa4dd4691bdbce73f1e015d16d55 100644 --- a/src/bignum.c +++ b/src/bignum.c @@ -3,12 +3,14 @@ typedef mpz_t* bignum_t; +/*Creation d'un grand nombre egal a 0*/ bignum_t bignum_zero(){ bignum_t x = (bignum_t) malloc(sizeof(mpz_t)); mpz_init(*x); return x; } +/*Initialise un nouvelle nombre et set son value a n*/ bignum_t bignum_from_int(int n){ bignum_t x = (bignum_t) malloc(sizeof(mpz_t)); mpz_init_set_si(*x, (signed long int) n); diff --git a/src/bignum.o b/src/bignum.o index 87c36c5d30c435065e0fcc6dbbcd6e36d2889817..aec244437d65e15a17a9d911b30d71016d1bd095 100644 Binary files a/src/bignum.o and b/src/bignum.o differ diff --git a/src/bst.o b/src/bst.o index 79c01065f8b1d8ae9505a123269ca7dfd7985dbb..8301b85de3362a39b1f522e7e7ffcacfaf4f2238 100644 Binary files a/src/bst.o and b/src/bst.o differ diff --git a/src/hash_tbl.h b/src/hash_tbl.h index f55732a4f57450f875cffa83cdbb5670364722bf..58acca62d1958ed80575aaa9bf8e39577f315616 100644 --- a/src/hash_tbl.h +++ b/src/hash_tbl.h @@ -1,7 +1,7 @@ #ifndef __HASH_TBL__ #define __HASH_TBL__ -#include "linked_list.h" +#include "list.h" struct hash_tbl { size_t (*h)(void*); diff --git a/src/hash_tbl.o b/src/hash_tbl.o index 855960b78165c3e7b86d90cbc0498d636f26f1a7..b19b47ec27c7b64b8c519672abd8fb47eedcaf00 100644 Binary files a/src/hash_tbl.o and b/src/hash_tbl.o differ diff --git a/src/list.c b/src/list.c index 62540e44334513697a26dac3896c73a0c5dc1026..76c3335d56e85f0da71ec63f228153ad40170ebc 100644 --- a/src/list.c +++ b/src/list.c @@ -9,9 +9,7 @@ struct cell_t { typedef struct cell_t* list_t; list_t list_empty(){ - list_t l = malloc(sizeof(list_t)); - l = NULL; - return l; + return NULL; } int list_is_empty(list_t l){ @@ -19,49 +17,70 @@ int list_is_empty(list_t l){ } 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; + + list_t tmp = malloc(sizeof(struct cell_t)); //pourquoi pas list_t? + tmp->val = x; + tmp->next = l; + if(list_is_empty(l)) { - return l1; + tmp->id = 1; + return tmp; } - l1->next = l; - return l1; + tmp->id = l->id+1; + return tmp; } list_t list_tail(list_t l){ return l->next; } +void* list_top(list_t l){ + return l->val; +} + void* list_pop(list_t* l){ - void * v = (*l)->val; - list_t newL = (*l)->next; - free(*l); - (*l) = newL; - return v; + + if (list_is_empty(*l)){ + return NULL; } -void* list_top(list_t l){ - return l->val; + list_t premierElement = *l; + void * val = list_top(premierElement); + *l = list_tail(premierElement); + free(premierElement); + + return val; } + + void list_destroy(list_t l, void (*freeVoid)(void*)){ + + list_t next; + while(l->next != NULL) { + next = list_tail(l); freeVoid(l->val); - free(l->next); + free(l); + l = next; } - } // 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; + + if (list_empty(l)){ + return NULL; + } + + list_t tmp = l; + + while(tmp != NULL) { + + if(eq(tmp->val,x)) { + return tmp->val; } - l = l->next; + tmp = tmp->next; } return NULL; } diff --git a/src/list.o b/src/list.o index bc93dde1ca0a1491408c0dc54e888853fe5a8392..d026d5dd8fabf86c17f668db4cd8a0195663fbc6 100644 Binary files a/src/list.o and b/src/list.o differ diff --git a/tests/bignum_tests b/tests/bignum_tests deleted file mode 100644 index 0af1d47e5a96a2e36175c58704fdf42ceb81fe4f..0000000000000000000000000000000000000000 Binary files a/tests/bignum_tests and /dev/null differ diff --git a/tests/list_tests b/tests/list_tests deleted file mode 100644 index 86c89d8353adbadffa612b58a54680a4dc45e9fe..0000000000000000000000000000000000000000 Binary files a/tests/list_tests and /dev/null differ