This commit is contained in:
2026-02-15 19:53:55 +01:00
parent 2162b3eadd
commit 6a9a4cc27b
6 changed files with 35 additions and 27 deletions
+6 -6
View File
@@ -59,13 +59,13 @@ int main(){
free(v->animal);
free(v);
*/
/*
struct vector *v = vector_init(2);
v = vector_resize(v, 4);
struct vector *v = vector_init(10);
v = vector_resize(v, 5);
printf("Resized capacity: %zu\n", v->capacity);
free(v->animal);
free(v);
*/
/*
struct vector *v = vector_init(2);
@@ -105,12 +105,12 @@ int main(){
struct animal *a = animal_from_fish("Blue", f);
free_animal(a);
*/
struct vector *v = vector_init(5);
/* struct vector *v = vector_init(5);
struct fish *f = fish_init("Trout", 8, 4, 1);
struct animal *a = animal_from_fish("Green", f);
v = vector_append(v, a);
vector_destroy(v);
*/
}
@@ -34,8 +34,6 @@ struct vector *vector_append(struct vector *v, struct animal *animal){
if(v == NULL || animal == NULL) return NULL;
if (v->capacity <= v->size) v = vector_resize(v, v->capacity * 2);
// TODO A voir si le realloc ajoute de l'espace a gauche ou a droite
// car sinon y a ecrasement de data
v->animal[v->size] = animal;
v->size ++;
return v;
@@ -70,5 +68,4 @@ void vector_destroy(struct vector *v){
free(v->animal);
free(v);
//free_animal(v->animal);
}