Linked List Unhandled Exception

Hello! I am getting an unhandled exception error with my appendNode function for my linked list. Can anyone help? Thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifndef NUMBERLIST
#define NUMBERLIST

using namespace std;

class HashTable;

class NumberList
{
      private:
             struct ListNode
             {
                  int studentID;  
                  ListNode * next;     

             ListNode()
                  { studentID = 0, next = NULL; };
                
             ListNode(int studID, ListNode * ptr = NULL)
                :studentID(studID), next(ptr)
                {}
             };  
             
             ListNode * head;                 //pointer to 1st node- head pointer
                           
                  
      public:
             NumberList()                     //constructor                 
                  { head = NULL; };
             ~NumberList();                   //destructor
             void appendNode(int);
             void insertNode(int);
             void deleteNode(int);
             bool searchList(int);
             void displayList() const;
             
             friend class HashTable;
};

#endif


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
void NumberList::appendNode(int id)
{
     ListNode * newNode;
     ListNode * nodePtr;
     
     newNode = new ListNode(id);
     newNode->next = NULL;
     
     if(!head)
	 {
          newNode = head;
	 }
     else
     {
         nodePtr = head;
         while (nodePtr->next)
               nodePtr = nodePtr->next;
         nodePtr->next = newNode;
     }
}
Last edited on
I'll give you the same advice I gave someone two days ago.

http://cplusplus.com/forum/beginner/69121/

Learn how to debug your program. No one is gonna compile your code. Tell us where the problem is so that we can help.
Topic archived. No new replies allowed.