#include<bits/stdc++.h>usingstd::cout;usingstd::endl;classLinkedlist;classNode{private:intdata;Node*next;public:Node():data(0),next(0){};Node(intx):data(x),next(0){};friendclassLinkedList;};classLinkedList{private:Node*first;public:LinkedList():first(0){};voidprintlist();voidpush_front(intx);voidpush_back(intx);voiderase(intx);voidclear();voidreverse();};voidLinkedList::printlist(){if(first==0){cout<<"List is empty.\n";return;}Node*current=first;while(current!=0){cout<<current->data<<" ";current=current->next;}cout<<endl;}voidLinkedList::push_front(intx){Node*newNode=newNode(x);newNode->next=first;first=newNode;}voidLinkedList::push_back(intx){Node*newNode=newNode(x);if(first==0){first=newNode;return;}Node*current=first;while(current->next!=0){current=current->next;}current->next=newNode;}voidLinkedList::erase(intx){Node*current=first;Node*previous=0;while(current!=0&¤t->data!=x){previous=current;current=current->next;}if(current==0){cout<<"There's no "<<x<<" in list.\n";return;}elseif(current=first){first=current->next;deletecurrent;current=0;return;}else{previous->next=current->next;deletecurrent;current=0;return;}}voidLinkedList::clear(){Node*current=first;first=first->next;deletecurrent;current=0;}voidLinkedList::reverse(){if(first==0||first->next==0)return;Node*previous=0,*current=first,*preceding=first->next;while(preceding!=0){current->next=previous;previous=current;current=preceding;preceding=preceding->next;}current->next=previous;first=current;}intmain(){LinkedListlist;list.push_front(1);list.push_front(2);list.printlist();return0;}