I want to input nodes and it's on void create() but it won't output on void display()
It gives a message like this:
Unhandled exception at 0x00EC966B in Project12.exe: 0xC0000005: Access violation reading location 0x00000000.
Break continue
The loop at line 73 creates a node but doesn't actually add it to the list.
This would be better C++ if you made some changes.
- remove initNode() and instead make a constructor for Node:
1 2 3 4
struct Node {
Node(int i) : info(i), next(nullptr) {}
// rest of your code
};
Also, if you make a separate class for the list itself then many of the functions become members of the class:
1 2 3 4 5 6 7 8 9 10 11
class List {
private:
Node *head;
public:
List() : head(nullptr) {}
~List();
addBegin();
create();
display();
};
Why do it this way? For one, it will remove some inconsistency: addBegin() currently takes a pointer to head, but create() uses the global variable called head. Also it means you can have multiple lists.