I am having trouble insearting values into a linked list, program keeps crashing. What is wrong with this function?
node looks like this:Code:void add_node() { Node *temp, *temp2; cout << "Please enter a number"; cin >> temp -> item; temp -> next = NULL; if (head == NULL) head = temp; else { temp2 = head; while (temp2 -> next != NULL) temp2 = temp2 -> next; temp2 -> next = temp; } }
Code:struct Node { int item; Node *next; };