Linked list segmentation fault. I'm guessing I'm doing something wrong with pointers here?

While(current! = NULL){ // if the iteration's ID is equal to the given ID return // false and delete the ListNode addition if(current->student->getID() == addition->getID()){ 2 return false; delete addition; // else if the next student ID in the list is greater than // the given ID break the while loop 1 }else if(current->next->student->getID() > addition->getID()){ break; } At the line I marked 1, you dereference current->next without ever checking if it is NULL or not. Also, at the line I marked 2, you end exectution, and then delete the pointer.

You should delete before you return if(current == NULL){ 3 current->next = addition; // else set addition next to current next next and current next to addition }else{ 4 addition->next = current->next->next; current->next = addition; } At the line marked 3, you dereference current only if it's NULL Bad juju. At the line marked 4, you dereference current->next without checking if it's NULL first. I think you meant to set addition->next to current->next anyway.

While(current! = NULL){ // if the iteration's ID is equal to the given ID return // false and delete the ListNode addition if(current->student->getID() == addition->getID()){ 2 return false; delete addition; // else if the next student ID in the list is greater than // the given ID break the while loop 1 }else if(current->next->student->getID() > addition->getID()){ break; } At the line I marked 1, you dereference current->next without ever checking if it is NULL or not. Also, at the line I marked 2, you end exectution, and then delete the pointer.

You should delete before you return. If(current == NULL){ 3 current->next = addition; // else set addition next to current next next and current next to addition }else{ 4 addition->next = current->next->next; current->next = addition; } At the line marked 3, you dereference current only if it's NULL. Bad juju.At the line marked 4, you dereference current->next without checking if it's NULL first.

I think you meant to set addition->next to current->next anyway.

I did all of your recommended fixes and it still isn't working. Thanks for pointing those out but can you find anything else that's wrong with it? – user1015524 Oct 28 at 20:07 @user1015524: Before every line with a pointername-> put in assert(pointername); Other than that, I can't see your updated code, so I can't comment on the updated code.

– Mooing Duck Oct 28 at 20:10 @user1015524: Find looks good, remove looks good, except it can't erase the first student. – Mooing Duck Oct 28 at 20:15 I updated the post to include my new code at the top – user1015524 Oct 28 at 20:29 @user1015524: looks good to my naked eye. To help further, I'm going to need more specific error messages.

You are using a debugger of some sort right? Visual Studio or gdb? – Mooing Duck Oct 28 at 20:50.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions