Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- template <typename T>
- class node {
- public:
- T data;
- node *next;
- node() :
- data( T() ), next( this ) { }
- node(const T& data, node* next) :
- data ( T(data) ), next( next ) { }
- };
- int main() {
- node<int> *front;
- front = new node<int>();
- front->data = 20;
- //----------- write your code here ------------
- node<int> *a,*b;
- a = new node<int>();
- b = new node<int>();
- a->data=10;
- b->data=30;
- front->next=b;
- a->next=front;
- b->next=NULL;
- front=a;
- // write code here such that
- // display will show 10, 20, 30
- //------------------- display --------------------
- node<int> *p = front;
- int i = 0;
- while (p!=NULL) {
- cout << i << ":" << p->data << endl;
- p = p->next;
- i++;
- }
- }
Add Comment
Please, Sign In to add comment