Question: 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

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!