Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please help me in C++. Here are a few requirements: only using void DoublyList::selecSuitor() don't forget to update the count don't forget to delete the
Please help me in C++. Here are a few requirements: only using void DoublyList::selecSuitor() don't forget to update the count don't forget to delete the node Thank you !!!
This is an old lab that it is usually done using a vector. The creative idea to change this to a linked list was proposed by one of your peers, Christian Marshall. Thank you, Christian! line she would continue counting from the beginning. For example, if there were 6 suitors then the elimination process would proceed as follows: Suitors: 123456 Suitor 3 will be eliminated! Suitor 6 will be eliminated! Suitor 4 will be eliminated! Suitor 2 will be eliminated! Suitor 5 will be eliminated! To win the princess, stand in position 1. Complete the function selectSuitor(), member of the DoublyList class, to determine in which position a suitor should stand to marry the princess if there are n suitors. A few more details: - The doubly-linked list has each node numbered, starting from the first node as 1 , the second at 2 , and so on, up to the last node which stores the position of the last suitor. - The easiest way to go around the list is by connecting the first and last node to make this a "circular" list. - Keep traversing the list and deleting every third node until you get to a single node, which holds the position of the winning suitor. - Every time you delete the third node, print the message, "Suitor \# will be eliminated!" where \# is the suitor's position. - Once you are left with one node, make sure all member variables and pointers in the remaining nodes are updated. Restriction: You may not create any containers (no array, no vector, no linked lists, etc.). All the work must be done in the linked list. The body of the function should be around 20 lines (excluding blank lines, curly brackets, and comments). If your code gets too long, you should revisit it and make it more efficient. Tips on efficiency/readability: - You only need 2 pointers and 2 nested loops. - The body of the function should be around 20 lines (excluding blank lines, curly brackets, and comments). If your code gets too long, you should revisit it and make it more efficient. - Choose descriptive identifiers (do NOT use "curr", or "ptr", or a single letter, except for "i"). your code in CodeCheck. This tool was successfully loaded in a new browser window. Reload the page to access the tool again. Functions.cpp Actual Expected Suitors: 123456 Suitor 3 will be eliminated! Suitor 6 will be eliminated! Suitor 4 will be eliminated! Suitor 2 will be eliminated! Suitor 5 will be eliminated! To win the princess, stand in position 1. Check final list is correct... Count: 1 Ptr prev: Ptr next: 0 First node: 1 Last node: 1 Suitors: 12345678910111213141516171819 Suitor 3 will be eliminated! Suitor 6 will be eliminated! Suitor 9 will be eliminated! Suitor 12 will be eliminated! Suitor 15 will be eliminated! Suitor 18 will be eliminated! Suitor 2 will be eliminated! Suitor 7 will be eliminated! Suitor 11 will be eliminated! Suitor 16 will be eliminated! Suitor 1 will be eliminated! Suitor 8 will be eliminated! Suitor 14 will be eliminated! Suitor 4 will be eliminated! Suitor 13 will be eliminated! Suitor 5 will be eliminated! Suitor 19 will be eliminated! Suitor 10 will be eliminated! To win the princess, stand in position 17Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started