list 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #define LIST
  2. struct LISTNAME {
  3. int size;
  4. LISTTYPE* data;
  5. };
  6. LISTNAME* LISTNEW() {
  7. LISTNAME* list = new LISTNAME[1];
  8. list->size = 0;
  9. list->data = new LISTTYPE[4];
  10. return list;
  11. }
  12. void listAdd(LISTNAME* list, LISTTYPE i) {
  13. int l = length(list->data);
  14. if(list->size >= l) {
  15. LISTTYPE* newData = new LISTTYPE[l * 2];
  16. for(int i = 0; i < l; i++) {
  17. newData[i] = list->data[i];
  18. }
  19. delete list->data;
  20. list->data = newData;
  21. }
  22. list->data[list->size] = i;
  23. list->size++;
  24. }
  25. int listGetLength(LISTNAME* list) {
  26. return list->size;
  27. }
  28. LISTTYPE listGetIndex(LISTNAME* list, int index) {
  29. return list->data[index];
  30. }
  31. void listDelete(LISTNAME* list) {
  32. delete list->data;
  33. delete list;
  34. }
  35. #end
  36. #define LISTNAME IntList #end
  37. #define LISTTYPE int #end
  38. #define LISTNEW listNewInt #end
  39. LIST
  40. #define LISTNAME FloatList #end
  41. #define LISTTYPE float #end
  42. #define LISTNEW listNewFloat #end
  43. LIST