Fix LList insertAt skipping one entry

This commit is contained in:
Theo Arends 2024-01-24 14:22:48 +01:00
parent 7f5e79415f
commit 79bc9a6b94
1 changed files with 4 additions and 0 deletions

View File

@ -208,6 +208,10 @@ T & LList<T>::addToLast(void) {
template <typename T> template <typename T>
T & LList<T>::insertAt(size_t index) { T & LList<T>::insertAt(size_t index) {
if (0 == index) {
return addHead(); // insert at the head
}
index--;
LList_elt<T> **curr_ptr = &_head; LList_elt<T> **curr_ptr = &_head;
size_t count = 0; size_t count = 0;
while (*curr_ptr) { while (*curr_ptr) {