I have a book inventory link list with a node struct that has 4 data types (name, price, amount, ISBN). It lets me enter all information but when it prints, it shows the previous final node twice, then my new node successfully, but then a segmentation fault.
You don't show constructors of Node. I presume implicit default constructor. Constructors are convenient.
Here, you essentially want to copy the 'book' to the new Node, don't you? Let copy constructor do the work:
1 2
void inventory::insert_sorted( Node book ) {
Node *insert = new Node { book };
However, your Node has a fifth member that your code does not explicitly initialize.
I bet the 'book' is no better, and thus the copy constructed Node will have the same issue.
What is the value of insert->next?
Lets make it explicit:
1 2 3
void inventory::insert_sorted( Node book ) {
Node *insert = new Node { book };
insert->next = nullptr;