Untitled
unknown
plain_text
8 months ago
477 B
11
Indexable
int vector_push_back(struct vector_t *a, int value) {
if(a == NULL || a->size > a->capacity || a->ptr == NULL || a->size < 0 || a->capacity < 1) {
return 1;
}
if(a->size == a->capacity) {
int* newptr = (int *) realloc(a->ptr,2*a->capacity*sizeof(int));
if (newptr == NULL) {
return 2;
}
a->ptr=newptr;
a->capacity*=2;
}
*(a->ptr + a->size) = value;
a->size++;
return 0;
}Editor is loading...
Leave a Comment