#include class linkedlist { struct node { int data; node *next; }; node *first; int num; public: linkedlist() { num=0; first=new node; first->data=0; first->next=NULL; } ~linkedlist() { removeall(); delete first; } void show() { node *p; for (p=first->next;p!=NULL;p=p->next) { printf("data=%d\n",p->data); } } void addnode(int i) { node *n; n=new node; n->data=i; if (first->next==NULL) n->next=NULL; else n->next=first->next; first->next=n; num++; } int getnum() { return num; } void removefromfirst() { if (first->next!=NULL) { node *p; p=first->next; first->next=p->next; num--; delete p; } } void removefromlast() { if (first->next!=NULL) { node *p; p=first; while (p->next->next!=NULL) { p=p->next; } node *temp; temp=p->next; delete temp; num--; p->next=NULL; } } void removeall() { for (int i=0;inext!=NULL) { node *p; p=first->next; first->next=p->next; delete p; } } num=0; } }; void main() { linkedlist list1, list2; list1.addnode( 5 ); list1.addnode( 10 ); list1.addnode( 11 ); list1.addnode( 15 ); list1.addnode( 99 ); list2.addnode( 47559 ); list2.addnode( 47600 ); list2.addnode( 47666 ); list2.addnode( 47999 ); list2.addnode( 47222 ); list2.addnode( 47111 ); list2.addnode( 47333 ); printf("number of list1 = %d\n",list1.getnum()); list1.show(); printf("\nnum of list2= %d\n",list2.getnum()); list2.show(); }