SE250:lab-3:jham005:arraylist.h
Jump to navigation
Jump to search
/* File: arraylist.h Date: 18 March 2008 Author: John Hamer Purpose: Resizable array-based list data structure */ typedef int element_t; /* choose your favourite type */ typedef struct { element_t *arr; /* start of the array */ int capacity; /* number of elements available */ int length; /* number of positions used, 0..capacity */ } ArrayList; void arraylist_init( ArrayList * ); void arraylist_clear( ArrayList * ); int arraylist_size( ArrayList * ); /* set and get an element by index */ void arraylist_put( ArrayList *, element_t, int index ); element_t arraylist_get( ArrayList *, int index ); /* add and remove elements from the end (largest index) */ void arraylist_push( ArrayList *, element_t ); element_t arraylist_pop( ArrayList * ); void ensure_capacity( ArrayList *, int required_capacity ); extern int ARRAYLIST_MIN_ALLOC; extern double ARRAYLIST_GROWTH_FACTOR; extern int ARRAYLIST_GROWTH_INCR; extern int ARRAYLIST_ALWAYS_MALLOC; /* Calling pattern: init { size, put, get, push, pop, ensure_capacity, clear } * clear */