#help with linked lists
30 messages · Page 1 of 1 (latest)
i dont have a previous struct variable
is this a doubly linked list or singly?
no, in that case, if you want to hold a pointer to the tail (why?), you need to run through the list
ok so its fine being tail-> next?
are you concerned with iterator invalidation? if not, there's a simpler way of dealing with the general case
i have to pass this test
would u like to see my entire file? i managed to complete all the other functions
what the hell is the point of tail in that case?
i think there are hidden tests aswell
but i think the else part looks a bit wrong to me but im not sure how to fix it
well, i'll avoid saying anything about optimizing the general case to not be O(n). i dont think it's necessarily relevant
while (current->next != element is wrong
or, well, you should realize you are stopping one node early
it seems you want to do so
so LinkedListElement_t* remove = current; is wrong
for (LinkedListElement_t* current = list->head; current->next != NULL)
would this work?
for (LinkedListElement_t* current = list->head; current->next != NULL; current->next) {
if (current->next == element) {
LinkedListElement_t* remove = current->next;
current->next = current->next->next;
free(remove);
}
}
i've replaced it with this
no
i dont get it