
Donald W. answered 04/08/22
Senior Software Engineer with over 25 years of industry experience
It's really hard to give you a good answer without seeing the rest of the file but I'll do my best. You'll want something like this:
void insertInOrder(List& list, int acctNum) {
Node *node = new Node(acctNum);
if (list.head == nullptr) {
list.head = node;
} else if (acctNum < list.head->acctNum) {
node->next = list.head;
list.head = node;
} else {
Node *curr = list.head;
while (curr->next != nullptr && curr->next->acctNum < acctNum) {
curr = curr->next;
}
node->next = curr->next;
curr->next = node;
}
}