I'm just playing around with a linked list trying to see how it all works. Why is my program printing 5 for both the head and the tail instead of 4 and 5 respectively?
struct Node {
int n;
Node *next;
};
class LinkedList {
public:
Node *head = NULL;
Node *tail = NULL;
};
int main() {
Node N;
LinkedList L;
L.head = &N;
L.tail = &N;
L.head->n = 4;
L.tail->n = 5;
cout << L.head->n << endl;
cout << L.tail->n << endl;
}