Question
#include using namespace std; struct Node{ int info; Node *link; }; Node *temp= NULL , *cur= NULL , *head= NULL , *tail= NULL ; void
#include
using namespace std;
struct Node{
int info;
Node *link;
};
Node *temp=NULL, *cur=NULL, *head=NULL, *tail=NULL;
void InsertFront()
{
temp = new Node;
cout<<"Enter Integer Data: ";
cin>>temp->info;
temp->link=NULL;
if (head==NULL)
{
head=temp;
tail=temp;
}
else
{
temp->link=head;
head=temp;
}
}
void InsertRear()
{
temp=new Node;
cout<<"Enter Integer Data: ";
cin>> temp->info;
temp->link=NULL;
if (head==NULL)
{
head=temp;
tail=temp;
}
else
{
tail->link=temp;
tail=temp;
}
}
void DeleteFront()
{
temp = head;
if(head==NULL)
{
cout<<"List is Empty!! ";
}
else
{
if(temp->link==NULL)
{
head=NULL;
tail=NULL;
}
else
{
head = head->link;
}
cout<<"Deleted:"<
delete temp;
}
cout< } void DeleteRear() { cur=head; temp=tail; if(head==NULL) { cout<< "List is Empty!! "; } else { if(cur->link==NULL) { head=NULL; tail=NULL; } else { while(cur->link!=tail) { cur=cur->link; } tail=cur; cur->link=NULL; } cout<<"Deleted: "< delete temp; } cout< } void PrintForward() { cur=head; if(head==NULL) { cout<<"List is Empty!! "; } else { cout<<"List display: "; while(cur!=NULL) { cout<< cur->info<<"\t"; cur=cur->link; } cout< } } int main(){ int choice; do{ cout << "1: Insert item at front "; cout << "2: Insert item at rear "; cout << "3: Delete item from front "; cout << "4: Delete item from rear "; cout << "5: Print List in forward direction "; cout << "6: Exit "; cout << "Enter your choice: "; cin>>choice; switch (choice){ case 1: InsertFront(); break; case 2: InsertRear(); break; case 3: DeleteFront(); break; case 4: DeleteRear(); break; case 5: PrintForward(); break; case 6: cout<<"Exiting Program "; break; default: cout<<"Error! wrong choice "; } }while (choice!=6); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started