3 ms·
Just in case someone is scratching their head over this... Let's come into the while loop body with data like this where H is the head pointer, C and E are ele
by jws 16y ago
Just in case someone is scratching their head over this...
Let's come into the while loop body with data like this where H is the head pointer, C and E are elements of the list...
H -> C /* head points to current node */
C->next -> E /* expired node is next*/
E->next -> NULL /* expired node is last */
if ( head->next == NULL)... /* no, head points to C, C->next is E */
if ( head->next->age > EXP...) /* yes, head->next is E and is expired */
head->next = head->next->next /* C->next is now NULL (E->next) */
head = head->next; /* head is now NULL */
/* back to the top of the loop */
while( *head != NULL... /* BANG! a NULL value just got dereferenced */