class Node {
private:
int element;
Node *next_node;
public:
Node(int = 0, Node * = nullptr);
int retrieve() const;
Node *next() const;
}
Constructor:
Node:Node(int e, Node * n) {
element = e;
next_node = n;
}
or
Node:Node(int e, Node * n):
element (e),
next_node (n) {
// empty constructor
}
Adding an element to the front
void List::push_front(int n) {
if (empty()) {
list_head = new Node(n, nullptr);
}else{
list_head = new Node(n, head());
}
}
void List::push_front(int n) {
list_head = new Node(n, head());
}
In [ ]: