Skip to content
Snippets Groups Projects
Commit 01ad5298 authored by Marta Boshkovska's avatar Marta Boshkovska
Browse files

Listes finies

parent 854be057
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
No preview for this file type
No preview for this file type
#ifndef __HASH_TBL__
#define __HASH_TBL__
#include "linked_list.h"
#include "list.h"
struct hash_tbl {
size_t (*h)(void*);
......
No preview for this file type
......@@ -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;
}
......
No preview for this file type
File deleted
File deleted
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment