class List {
ListNode *head;
ListNode *prev;
};
class ListNode {
int data;
ListNode *next;
friend class List;
ListNode(int d, ListNode *n) : data(d), next(NULL) {}
void insertM(int d) {
ListNode *ptr, *temp, *curr;
ptr = head;
while (ptr->data < d) {
prev = ptr;
ptr = ptr->next;
} // end while
temp = prev->next;
curr = new ListNode(d, ptr);
curr->next = prev->next; // or temp->next
prev->next = curr;
;
}
};
List mylist;
In this function, I'm trying to add a node in the middle of linked list. Other functions add items to the back and front just fine. When I add in the middle of the list, my prev->next links to curr just fine, but curr->next points to NULL.
I have been trying to make this program work for past 1.5 hours. I'll appreciate your help. This is homework.