#include "arraylist.h" #include #include ArrayList *makeList() { ArrayList *ans = (ArrayList *)malloc(sizeof(ArrayList)); ans->capacity = 1; ans->size = 0; ans->data = (int *)malloc(sizeof(int) * ans->capacity); return ans; } void destroyList(ArrayList *a) { free(a->data); a->data = NULL; free(a); } void add(ArrayList *to, int value) { if (to->size >= to->capacity) { to->capacity *= 2; to->data = realloc(to->data, sizeof(int)*to->capacity); } to->data[to->size++] += value; } void show(ArrayList *list) { printf("["); for(int i = 0; i < list->size; i+=1) { if(i != 0) printf(", "); printf("%d", list->data[i]); } printf("]\n"); }