1

所以我试图向arraylist添加一个特定的值。程序可以工作,但是当我检查是否添加了值时,我每次都得到相同的数字。

void arrayListInsert(struct ArrayList * list, unsigned index, short value){
    if(index > list->size){
        printf("Index bigger than size ");
        return;
    }
    if(list->size == list->capacity){
        short *array=(short *)realloc(list->array,2*sizeof(list->capacity));
        list->capacity = list->capacity * 2;
        memmove(&array[index],&list->array[list->size-1],sizeof(short *));
        array[index]=value;
        list->array=array;
        list->size++;
    }
}
4

0 回答 0