aiThanet

Untitled

Apr 10th, 2016
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. template <typename T>
  7. class node {
  8.   public:
  9.     T data;
  10.     node *next;
  11.  
  12.     node() :
  13.       data( T() ), next( this ) { }
  14.  
  15.     node(const T& data, node* next) :
  16.       data ( T(data) ), next( next ) { }
  17. };
  18.  
  19. int main() {
  20.   node<int> *front;
  21.   front = new node<int>();
  22.  
  23.   front->data = 20;
  24.  
  25.   //----------- write your code here ------------
  26.  
  27.     node<int> *a,*b;
  28.     a = new node<int>();
  29.     b = new node<int>();
  30.     a->data=10;
  31.     b->data=30;
  32.  
  33.     front->next=b;
  34.     a->next=front;
  35.     b->next=NULL;
  36.     front=a;
  37.  
  38.   // write code here such that
  39.   // display will show 10, 20, 30
  40.  
  41.  
  42.   //------------------- display --------------------
  43.   node<int> *p = front;
  44.   int i = 0;
  45.   while (p!=NULL) {
  46.     cout << i << ":" << p->data << endl;
  47.     p = p->next;
  48.     i++;
  49.   }
  50.  
  51. }
Add Comment
Please, Sign In to add comment