Appending Node to DLL

I'm trying to append node's to a new list. The program currently crashes at the while loop.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
void DLL:append(string ss, string name, int & count){
  Node *temp;
  Node *newNode = new Node();
  newNode->ssn = ss;
  newNode->name = name;
  newNode->next = NULL;
  newNode->prev = NULL;
  temp = headPtr;

  if(headPtr == NULL){
   headPtr = newNode;
   count++;
  }else{
   while(temp->next != NULL){
    temp = temp->next;
   }
   newNode->prev = temp;
   newNode->next = NULL;
   temp->next = newNode;
   count++;
  }
 }
}


I've also tried using this instead of that while loop, same result however:

1
2
3
4
while(temp != NULL){
 ...
 temp = temp->next
}


Changed the second case above to

1
2
3
4
while(temp->next != NULL){
 ...
 temp = temp->next;
}


It got through the entire thing and then displayed characters of other languages, along with symbols, etc - then followed by about every folder on my surface until it finally crashed :c

Any help would be greatly appreciated!
Topic archived. No new replies allowed.