"menu driven program to delete in linked list" Code Answer's
You're definitely familiar with the best coding language C++ that developers use to develop their projects and they get all their queries like "menu driven program to delete in linked list" answered properly. Developers are finding an appropriate answer about menu driven program to delete in linked list related to the C++ coding language. By visiting this online portal developers get answers concerning C++ codes question like menu driven program to delete in linked list. Enter your desired code related query in the search bar and get every piece of information about C++ code related question on menu driven program to delete in linked list.
menu driven program to delete in linked list
#include <iostream>
using namespace std;
class node
{
public:
int data;
node*next;
};
node*head=NULL;
void insertlist(int val)
{
node*temp=new node;
temp->data=val;
if(head==NULL)
{
temp->next=head;
head=temp;
}
else
{
temp->next=head;
head=temp;
}
}
void delete_start()
{
if(head==NULL)
{
cout<<"no element in the list :: nothing to be deleted:"<<endl;
}
else
{
node*temp=new node;
temp=head;
head=head->next;
delete(temp);
}
}
void delete_end()
{
if(head==NULL)
{
cout<<"no element in the list :: nothing to be deleted:"<<endl;
}
else
{
node *temp=new node;
temp=head;
node*ptr=new node;
while(temp->next->next!=NULL)
{
temp=temp->next;
}
ptr=temp->next;
temp->next=NULL;
delete ptr;
}
}
void delete_any(int val)
{
node*temp=new node;
if(head==NULL)
{
cout<<"no element in the list :: nothing to be deleted:"<<endl;
}
else
{
if(head->data==val)
{
temp=head;
head=head->next;
delete temp;
}
else
{
node*ptr=new node;
ptr=head;
while(ptr->next!=NULL)
{
if(ptr->next->data==val)
{
temp=ptr->next;
ptr->next=ptr->next->next;
delete temp;
}
ptr=ptr->next;
}
}
}
}
void printf()
{
node*temp=new node;
temp=head;
while(temp!=NULL)
{
cout<<temp->data<<" ";
temp=temp->next;
}
cout<<endl;
}
int main()
{
int n;
int t;
cin>>t;
while(t--)
{
cout<<"enter the value to be inserted in the list:"<<endl;
cin>>n;
insertlist(n);
}
printf();
int s;
while(1)
{
cout<<"1-delete from the start"<<endl<<"2-delete from the end"<<endl<<"3-delete any element"<<endl<<"4-exit"<<endl;
cout<<"enter your choice:"<<endl;
cin>>s;
switch(s)
{
case 1:
{
delete_start();
printf();
break;
}
case 2:
{
delete_end();
printf();
break;
}
case 3:
{
int a;
printf();
cout<<"enter the value to be deleted:"<<endl;
cin>>a;
delete_any(a);
printf();
break;
}
case 4:
{
exit(0);
}
default:
{
cout<<"invalid opertaion:"<<endl;
}
}
}
return 0;
}
All those coders who are working on the C++ based application and are stuck on menu driven program to delete in linked list can get a collection of related answers to their query. Programmers need to enter their query on menu driven program to delete in linked list related to C++ code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about menu driven program to delete in linked list for the programmers working on C++ code while coding their module. Coders are also allowed to rectify already present answers of menu driven program to delete in linked list while working on the C++ language code. Developers can add up suggestions if they deem fit any other answer relating to "menu driven program to delete in linked list". Visit this developer's friendly online web community, CodeProZone, and get your queries like menu driven program to delete in linked list resolved professionally and stay updated to the latest C++ updates.