Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a doubly-linked list of a length determined by user input Write a main () routine in which the user is asked the number of

Create a doubly-linked list of a length determined by user input

Write a main() routine in which the user is asked the number of nodes to create in the list (number greater than or equal to zero) then create the following type of linked list (use a loop to initialize list) based on the number of nodes requested:

Assume entries in a linked list are of type struct listrec:

struct listrec { struct listrec *prev; float value; struct listrec *next; }; listrec *head, *tail;

I have the following, I'm just not sure how to make a doubly-linked list based off a dynamic input:

#include #include using namespace std;

int main() { struct listrec { struct listrec *prev; float nbr; struct listrec *next; };

listrec *head, *tail;

float userin;

cout << " Please enter the number of nodes you would like to create "<< endl; cin>>userin; while(!(cin >> userin) || userin < 0) { cin.clear(); cin.ignore(numeric_limits::max(), ' '); cout << "Invalid input, the input must be zero or greater and not a letter" << endl; }

head = NULL; current = NULL; for(int i =1; i < userin+1; i++) { if (head==NULL) { head = new node; head -> nbr = i; head -> next = NULL; current = head; } else { current -> next = new node; current = current -> next; current -> tail = NULL; current -> nbr = i; current -> next = NULL; } }

}

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

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

More Books

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago