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:
parent
269b1f7451
commit
e0115dd7d9
@ -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--;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user