Question: Modify the above program to insert a new node in the middle of list (take a node data from user, search the node and insert

  1. Modify the above program to insert a new node in the middle of list (take a node data from user, search the node and insert new node after this node).
  2. Modify the above program to include an operation for searching a value from the linked list.
  3. Write a function to delete a matching node (by search) from a linked list of integers. You can use the example given above to develop your solution. In your answer, provide only the required function.

Using C++ language..

struct Node{
int info;
Node *link;
};
Node *temp=NULL, *cur=NULL, *head=NULL, *tail=NULL;
B. Insert at Front
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;
}
}
C. Insert at Rear
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;
}
}
D. Delete from Front
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:"<info <<" ";
delete temp;
}
cout<
}
E. Delete from Rear
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: "<info << " ";
delete temp;
}
cout<
}
F. Print Forward
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<
}
}
G. Driver Code
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;
}
1.Modify the above program to insert a new node in the middle of list (take a node data from user, search the node and insert new node after this node).
2. Modify the above program to include an operation for searching a value from the linked list.
3. Write a function to delete a matching node (by search) from a linked list of integers. You can use the example given above to develop your solution. In your answer, provide only the required function.
using c++ language
*singly linked list*

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!