#import "YSArray.h" #include #include @implementation YSArray -(id) init { self = [super init]; array = malloc(sizeof(id)); //allocate for one id return self; } -(void) addObject: (id) theObject { if (array == NULL) { printf("%s\n", "addObject Init"); array = malloc(sizeof(id)); if (array == NULL) { return; } } else { array = realloc(array, (count + 1) * sizeof(id)); if (array == NULL) { return; } } array[count++] = theObject; } -(void) removeObject: (unsigned int) index { if (count == 0 || count == 1) { array[0] = NULL; return; } if (index >= count) { return; } if (index == count - 1) { array[count - 1] = NULL; } //hope count > index; memcpy(&array[index], &array[index + 1], (count - index) * sizeof(id)); } @end