#include template class linkedlist { struct node { TYPE data; node *next; }; node *first; int num; node *nav; public: linkedlist() { num=0; first=new node; first->next=NULL; nav=new node; } ~linkedlist() { removeall(); delete first; delete nav; } void start() { nav=first->next; } bool notnull() { return nav!=NULL; } void next() { nav=nav->next; } TYPE *getnode() { return &nav->data; } void addnode(TYPE 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; } delete p->next->next; 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 list; list.addnode(5); list.addnode(7); list.addnode(45); list.addnode(6); list.addnode(8); list.addnode(9); for(list.start();list.notnull();list.next()) { printf("data=%d\n",*list.getnode()); } }