I'm taking a data structures course using C++, and we're supposed to implement a simple single linked-list structure.
I have all the other methods figured out, but when I check if the list is empty when it actually is, the program crashes, causing a segmentation fault.
When a list is empty, my linked list structure is supposed to look like:
HEAD -> NULL
Whereas if it is not empty, it should look like:
HEAD -> ...... -> NULL
My isListEmpty() looks like:
bool singleList::isListEmpty(void) {
return (head->next == NULL);
}
I'm pretty sure the core is dumped when I try to access a null pointer, but I'm not sure where. Any suggestions on where I should look?
Thanks.
--Edited--
Sorry, I wasn't clear enough.
I'm pretty sure head itself is NOT a null pointer, because while checking if my code worked, I worked with something like:
list.list_insert_front(guy1);
list.list_insert_front(guy2);
list.list_remove(guy1);
list.list_remove(guy2);
list.isListEmpty(); //This line causes segmentation fault.