aiThanet

Untitled

Apr 10th, 2016
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 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>(10,
  22.       new node<int>(20,
  23.         new node<int>(30,
  24.           new node<int>(40,NULL)
  25.         )
  26.       )
  27.   );
  28.  
  29.  
  30.   //----------- write your code here ------------
  31.  
  32.   // write code here such that
  33.   // display will show 10, 30
  34.     front->next=front->next->next;
  35.     front->next->next=NULL;
  36.  
  37.   //------------------- display --------------------
  38.   node<int> *p = front;
  39.   int i = 0;
  40.   while (p!=NULL) {
  41.     cout << i << ":" << p->data << endl;
  42.     p = p->next;
  43.     i++;
  44.   }
  45.  
  46. }
Add Comment
Please, Sign In to add comment