Ask coding questions

← Back to all posts
signal: segmentation fault (core dumped) out of nowhere

I'm coding some college exercises for simple and doubly linked lists and I'm facing an issue that doesn't make any sense, for me at least.
Basically the list is ordered in ascending order by key and it was working perfectly till I added the following part to the "insertSimple" function (lines 25-28):
else if (link-> key < head-> key) {
link-> next = head;
head = link;

This piece of code is basically to check if the new node has a key lower than the first one on the list. After adding this the code started to return the 'segmentation fault' error. I don't know how this simple check would cause this, if someone could help me with that I would really appreciate it.

Edit: Apparently the error only happens when after I run the "invertOrder()" function, which wasn't even the function that I changed for the issue to start