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:
+11
-6
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user