1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- #define LIST
- struct LISTNAME {
- int size;
- LISTTYPE* data;
- };
- LISTNAME* LISTNEW() {
- LISTNAME* list = new LISTNAME[1];
- list->size = 0;
- list->data = new LISTTYPE[4];
- return list;
- }
- void listAdd(LISTNAME* list, LISTTYPE i) {
- int l = length(list->data);
- if(list->size >= l) {
- LISTTYPE* newData = new LISTTYPE[l * 2];
- for(int i = 0; i < l; i++) {
- newData[i] = list->data[i];
- }
- delete list->data;
- list->data = newData;
- }
- list->data[list->size] = i;
- list->size++;
- }
- int listGetLength(LISTNAME* list) {
- return list->size;
- }
- LISTTYPE listGetIndex(LISTNAME* list, int index) {
- return list->data[index];
- }
- void listDelete(LISTNAME* list) {
- delete list->data;
- delete list;
- }
- #end
- #define LISTNAME IntList #end
- #define LISTTYPE int #end
- #define LISTNEW listNewInt #end
- LIST
- #define LISTNAME FloatList #end
- #define LISTTYPE float #end
- #define LISTNEW listNewFloat #end
- LIST
|