/* Header info for arraylist.c. The ArrayList struct contains the data necessary to maintain the list; but since C is not object-oriented, the traditional "methods" that you're accustomed to are instead functions that take a pointer to that struct as a parameter. */ struct ArrayList { // A pointer to a traditional C array to hold data int* array; // The size of the actual C array that you have allocated int memorySize; // The virtual size of the ArrayList, i.e. how much data is in it // from the user's perspective int size; }; /* Typing "struct ArrayList" all the time is cumbersome, this sets it up so you can just type "ArrayList" instead. */ typedef struct ArrayList ArrayList; /* Function prototypes. */ /* Take an already existing ArrayList as a parameter. (Do not create an ArrayList stuct inside this function. Set its internal memory size to match the value given in the parameter, create an assign an appropriate traditional C array to hold the actual data, and initialize the size variable to 0. */ void init(ArrayList *list, int memorySize); /* Print out the array list for debugging purposes. */ void print(ArrayList *list); /* Insert value at location inside the ArrayList. If there is already data at that location, insert slides the rest of the data down one position to make room for the new value. (Make sure you use memmove to do this efficiently.) Returns 1 if success, and 0 if the location is invalid (less than 0, or greater than the size as perceived by the user). Inserting at the very end of the array (at position equal to the perceived size) is fine. If the internal array is too small, a new one of twice the size is created. The values are copied (efficiently using memmove, not one-by-one), the ArrayList struct is appropriately updated, and the old array is freed. */ int insert(ArrayList *list, int location, int value); /* Obtains value at location inside the ArrayList. Returns 1 if success, and 0 if the location is invalid (less than 0, or greater than the size as perceived by the user). The value itself is returned through the parameter "value". */ int get(ArrayList *list, int location, int *value); /* Deletes value at location inside the ArrayList. Returns 1 if success, and 0 if the location is invalid (less than 0, or greater than the size as perceived by the user). When an item is deleted, everything else past it in the array should be slid down (efficiently using memmove, not one-by-one). The internal array itself does not need to be compressed, i.e., you don't need to halve it in size if it becomes half full, or anything like that. */ int delete(ArrayList *list, int location);