#include #include #include #include using namespace std; class Array { struct node { char *str; int item; struct node *next; }*p; public : Array() { p = NULL; } ~Array() { node *s; if(p == NULL) return; while(p != NULL) { s = p->next; delete p->str; delete p; p = s; } } void getValue(int i) { int k=0; node *s = p; while(s != NULL) { if(k == i) cout << s->str << " " << s->item << endl; s = s->next; k++; } } void putValue(int j) { node *s,*t; if(p == NULL) { t = new node; t->str = new char[20]; t->item = j; t->str = "Hello"; t->next = NULL; p = t; } else { t = p; while(t->next != NULL) t = t->next; s = new node; s->str = new char[20]; s->item = j; s->str = "Hello"; s->next = NULL; t->next = s; } } void display() { node *t; t = p; while( t != NULL) { cout << t->str << " " << t->item << " "; t = t->next; } } Array(const Array &a); }; Array::Array(const Array &a) { node *s,*t,*r; s = a.p; while(s != NULL) { if(t == NULL) { t = new node; t->str = new char[20]; t->item = s->item; t->str = "Priya"; t->next = NULL; p = t; } else { t = p; while(t->next != NULL) t = t->next; r = new node; r->str = new char[20]; r->item = s->item; r->str = "Priya"; r->next = NULL; t->next = r; } s = s->next; } cout << "copy done"; } int main() { Array num; int i; for(i=0;i<10;i++) num.putValue(i); for(i=9;i>=0;i--) num.getValue(i); cout << "\n"; Array x(num); x.display(); for(i=9;i>=0;i--) x.getValue(9-i); getch(); return 0; }