Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#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:"<info <<" ";

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: "<info << " ";

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;

}

  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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students also viewed these Databases questions

Question

1. Which position would you take?

Answered: 1 week ago