made examples/demos for vectors && files && lists | also fixed a bug with the vector and list size and popping, explained in the adjacent comment

This commit is contained in:
Odweta
2023-12-22 19:04:08 +01:00
parent 2f1c78ce52
commit b9c93116bc
9 changed files with 146 additions and 75 deletions
+11 -6
View File
@@ -96,12 +96,17 @@ listCleanup(list_t* l) {
void*
listPop(list_t* l) {
vector_t *first_ptr = (vector_t *)vectorPop((vector_t *)l->data);
void *ptr = vectorPop(first_ptr);
l->size -= 1;
if (l->size != 0) {
vector_t *first_ptr = (vector_t *)vectorPop((vector_t *)l->data);
void *ptr = vectorPop(first_ptr);
l->size -= 1;
if (l->size <= l->capacity / 2) l->capacity /= 2;
if (l->capacity == 0) l->capacity = 1;
if (l->size <= l->capacity / 2) l->capacity /= 2;
if (l->capacity == 0) l->capacity = 1;
return ptr;
return ptr;
} else {
// cannot pop when there is no value in the list
return NULL;
}
}