Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

n C++ , write a program to create a doubly linked list from an input file (input.txt). The number of items is unknown. Then, the

n C++, write a program to create a doubly linked list from an input file (input.txt). The number of items is unknown. Then, the program should display the results and saved into an output file (output.txt).

Use these concepts for the program:

1) DO NOT USE classes 2) Use Struct Node 3) Use Double Linked Concepts 4) MUST HAVE input and output file

Instructions:

1. (Delete from head) Prompt the user for a node number. Starting from the head, moving forward, go to the node and delete it.

2. (Delete from tail) Prompt the user for another node number. Starting from the tail, moving backward, go to the node and delete it.

3. Write the contents of the modified list into the file (output.txt).

NOTE: The node to be deleted can be the head, the tail or something in the middle. If there is only one node in the list and it is being deleted, then both the head and tail are affected by this.

Example of delete function:

void deleteBeg(int delBeg,struct node *&head,struct node *&tail)

{

struct node *current=head;

while (--delBeg >0 ){ //If 0, then we have landed on the

node to be deleted

current=current->next; //go to node that needs to be

deleted

if (current==NULL) //If delBeg is invalid and we go

outside, get out

break;

}

if (current!=NULL) //If delBeg is 0 coming into the

function or invalid do nothing

adjust(current,head,tail); //current contains the node to

be deleted

}

-----------------------------------

Result:

Input file

59 22 23 58

Which item do you want to delete from the beginning? 3 //the first delete would remove 23 from the list.

Which item do you want to delete end? 2 //The second delete would remove 22 from the list.

Output file and display:

59 58

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_2

Step: 3

blur-text-image_3

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

Main Memory Database Systems

Authors: Frans Faerber, Alfons Kemper, Per-Åke Alfons

1st Edition

1680833243, 978-1680833249

Students also viewed these Databases questions

Question

What are resource constraints? Give some examples.

Answered: 1 week ago