You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
926 B
Objective-C

#import "YSArray.h"
#include <string.h>
#include <stdio.h>
@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