1
1
mirror of https://github.com/theoludwig/libcproject.git synced 2024-11-08 22:31:31 +01:00

fix: error in array_list_remove (always removed the last index and not the index given) (#6)

Co-authored-by: Maxime Rumpler <mrumpler68@gmail.com>
This commit is contained in:
ChepakiLeCookie 2023-10-13 11:04:38 +02:00 committed by GitHub
parent 269b1f7451
commit e0115dd7d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -25,8 +25,8 @@ void array_list_remove(struct array_list* list, size_t index) {
if (index >= list->size) {
return;
}
for (size_t i = index + 1; i < list->size - 1; i++) {
list->data[i - 1] = list->data[i];
for (size_t i = index; i < list->size - 1; i++) {
list->data[i] = list->data[i + 1];
}
list->size--;
}

View File

@ -34,4 +34,15 @@ void array_list_test() {
assert(array_list_get(list, 100) == (void *)95);
array_list_free(list);
list = array_list_initialization();
array_list_add(list, (void *)'a');
array_list_add(list, (void *)'b');
array_list_add(list, (void *)'c');
array_list_remove(list, 1);
assert(array_list_get(list, 0) == (void *)'a');
assert(array_list_get(list, 1) == (void *)'c');
assert(list->size == 2);
array_list_free(list);
}