Skip to content
Snippets Groups Projects
Commit c76f1105 authored by Alec's avatar Alec
Browse files

kek v2

parent 3a0bd826
Branches main
No related tags found
No related merge requests found
...@@ -48,7 +48,7 @@ void vector_push(vector *v, type item) ...@@ -48,7 +48,7 @@ void vector_push(vector *v, type item)
void vector_pop(vector *v, type item) void vector_pop(vector *v, type item)
{ {
assert(v->length>0); assert(v->length>0);
if (v->length-1 == v->capacity/2) if (v->length-1 == v->capacity/4)
{ {
v->capacity /=2; v->capacity /=2;
v->data = realloc(v->data, v->capacity * sizeof(type)); v->data = realloc(v->data, v->capacity * sizeof(type));
...@@ -104,9 +104,11 @@ void vector_insert(vector *v, type element, int index) ...@@ -104,9 +104,11 @@ void vector_insert(vector *v, type element, int index)
void vector_empty(vector *v) void vector_empty(vector *v)
{ {
free(v->data); for (int i = v->length; i > 0; i--)
vector v2 = vector_create(); {
v = &v2; vector_remove(v, i);
}
v->data = realloc(v->data, VECTOR_INIT_CAPACITY * sizeof(type));
} }
void vector_free(vector *v) void vector_free(vector *v)
...@@ -123,7 +125,7 @@ void vector_print(vector *v, void (*print)(type)) ...@@ -123,7 +125,7 @@ void vector_print(vector *v, void (*print)(type))
print(v->data[i]); print(v->data[i]);
printf(","); printf(",");
} }
printf("]"); printf("]\n");
} }
vector vector_map(vector *v, type (*f)(type)) vector vector_map(vector *v, type (*f)(type))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment