Node* revHead; // ... while(current != NULL) { //check if it the first one being added if(revHead == NULL)
You do not initialize revHead , but use it. (I hope itβs already clear to you that revHead is a local variable used to store a memory address, not something that exists outside of a method / procedure)
The revHead storage revHead is automatic (also in the local teleobject). In C++ , when you make such an announcement, there is no guarantee that the value will be 0 .
(if the storage class is not of the static type or the global variable, where it is automatically initialized to 0 , unless another value is specified. In your case, the variable has the storage class of the auto type, which means that it is locally defined in the function, and when the local variable is declared without specifying a value, this value is garbage. Keep in mind that with the next C ++ C++0x auto keyword has a new meaning).
The value in your case is garbage, which causes the if crash. Read more here: Link
Do
Node* revHead = NULL;
Keep in mind that you may have errors like this in another part of your code.
source share