Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Node {
  5.  
  6. public:
  7.  int data;
  8.  Node* nxtNode;
  9.  Node(int _data) {
  10.   data=_data;//Data
  11.   nxtNode=NULL;//Next element pointer
  12.  }
  13. };
  14.  
  15. class LinkedList {
  16.  Node* current;
  17. public:
  18.  LinkedList() {
  19.   current=NULL;
  20.  }
  21.  void insert(Node * _node) {
  22.   if (current==NULL) {
  23.    current= _node;//first node
  24.   } else {
  25.    (*_node).nxtNode=current;
  26.    current= _node;//2nd node starts
  27.   }
  28.  }
  29.  
  30.  void displayAll() {
  31.   Node* tmp=current;
  32.   while (tmp!=NULL) {
  33.    cout << (*tmp).data <<endl;
  34.    tmp=(*tmp).nxtNode;
  35.   }
  36.  }
  37. };
  38.  
  39. int main() {
  40.  Node* firstNode=new Node(1);
  41.  Node* secondNode=new Node(2);
  42.  Node* thirdNode=new Node(3);
  43.  LinkedList ll;
  44.  ll.insert(firstNode);
  45.  ll.insert(secondNode);
  46.  ll.insert(thirdNode);
  47.  ll.displayAll();
  48.  return 0;
  49. }