#include #include #include class Node { private: int data; Node* next; public: int getData() { return data; } void setData(int data) { this->data=data; } Node* getNext() { return next; } void setNext(Node* next) { this->next=next; } }; class LinkList { private: Node* head; public: LinkList() { head=NULL; } void addNode(int data) { Node* newNode=new Node; newNode->setData(data); newNode->setNext(head); head=newNode; } int deleteNode() { if(head==NULL) { cout<<"List is empty\n"; return 0; } else { int ret=head->getData(); Node* temp=head; head=head->getNext(); delete temp; return ret; } } }; void main() { clrscr(); LinkList* list=new LinkList; int choice; cout<<"1: Add Node\n"; cout<<"2: Delete Node\n"; cout<<"3: Exit\n"; while(1) { cout<<"\n\nEnter your choice:"; cin>>choice; switch(choice) { case 1: int data; cout<<"Enter the data for the new node: "; cin>>data; list->addNode(data); break; case 2: cout<<"The deleted node is: " << list->deleteNode(); break; case 3: exit(0); } } }