#include <iostream>
using namespace std;
class Node {
public:
int data;
Node* nxtNode;
Node(int _data) {
data=_data;//Data
nxtNode=NULL;//Next element pointer
}
};
class LinkedList {
Node* current;
public:
LinkedList() {
current=NULL;
}
void insert(Node * _node) {
if (current==NULL) {
current= _node;//first node
} else {
(*_node).nxtNode=current;
current= _node;//2nd node starts
}
}
void displayAll() {
Node* tmp=current;
while (tmp!=NULL) {
cout << (*tmp).data <<endl;
tmp=(*tmp).nxtNode;
}
}
};
int main() {
Node* firstNode=new Node(1);
Node* secondNode=new Node(2);
Node* thirdNode=new Node(3);
LinkedList ll;
ll.insert(firstNode);
ll.insert(secondNode);
ll.insert(thirdNode);
ll.displayAll();
return 0;
}