Segmentation-Fault usually means that you try to access some part of the memory that is not under the control of or is a restricted region of your program. Such things happen when you try to access invalid pointers or dereference iterators outside the container bounds.
Since you say it yourself, that you can display the content of testlist
, I'm going stick to the same advice Dark gave you: You probably haven't inserted anything into studentlist
before acessing it. The dec/inc operators of iterators have to be able to access the storage element of the container to find the next one in general. If the iterator is invalid it will likely access memory locations out of range.
Or does your program crash in the first for loop?
Secondly, why are you inserting so complicated? You do not need to take care of the prev/next handling of the list. That's what these container classes are for: To abstract away the detail. If you want better memory allocation you would specify a separate allocator for that purpose.