In an ancient land, the beautiful princess Eve had many suitors. She decided on the following procedure to determine which suitor she would marry. First, all of the suitors would be lined up one after the other and assigned numbers. The first suitor would be number 1, the second number 2, and so on up to the last suitor, number n. Starting at the first suitor she would then count three suitors down the line (because of the three letters in her name) and the third suitor would be eliminated from winning her hand and removed from the line. Eve would then continue, counting three more suitors, and eliminating every third suitor. When she reached the end of the line she would continue counting from the beginning. For example, if there were 6 suitors then the elimination process would proceed as follows: Suitors: 1 2 3 4 5 6 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"). To easily debug your code, you should work on Visual Studio. Use the files available in the doubly-linked list chapter and create a list that stores integers from 1 to n (the number of suitors). Once it is working, you can paste your code in CodeCheck.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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 !!!

Functions.cpp
1 #include "DoublyList.h"
2
3 using namespace std;
5
// Definition function selectSuitor()
6 // Do not create any containers.
7 // Your code here...
8
9 void DoublyList::selectSuitor()
{
10
11
12
DLLNode* current = first;
count++;
13 delete current;
14 }
15
CodeCheck
Reset
Running Main.cpp
Actual
Expected
Suitors: 1 2 3 4 5 6
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: 0
Ptr next: 0
First node: 1
Last node: 1
Suitors: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Suitor 3 will be eliminated!
Suitor 6 will be eliminated!
Suitor 9 will be eliminated!
Suitor 12 will be eliminated!
Suffor 12 Will be eliminated:
Sultor
Suitor 15 will be eliminated!
eliminated!
will be
Suitor 18 will be
Sultor 18 will be eliminated!
eliminated!
Suitor 2 will be
eliminated!
Suitor 7 will be
Suflor WiLL
Suitor 11 will be
Sultor it will be eliminated
eliminated!
Sultor
Suitor
to will be eliminated!
16 will be
eliminated!
Sultor I will be eliminated!
Suitor 1 will be
eliminated!
eliminated!
Suitor 8 will be
Sultor
Suitor
eliminated:
14 will be
eliminated!
Sultor will be eliminated
Suitor 4 will be eliminated!
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 17.
Check final list is correct...
eliminated:
eliminated!
Transcribed Image Text:Functions.cpp 1 #include "DoublyList.h" 2 3 using namespace std; 5 // Definition function selectSuitor() 6 // Do not create any containers. 7 // Your code here... 8 9 void DoublyList::selectSuitor() { 10 11 12 DLLNode* current = first; count++; 13 delete current; 14 } 15 CodeCheck Reset Running Main.cpp Actual Expected Suitors: 1 2 3 4 5 6 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: 0 Ptr next: 0 First node: 1 Last node: 1 Suitors: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Suitor 3 will be eliminated! Suitor 6 will be eliminated! Suitor 9 will be eliminated! Suitor 12 will be eliminated! Suffor 12 Will be eliminated: Sultor Suitor 15 will be eliminated! eliminated! will be Suitor 18 will be Sultor 18 will be eliminated! eliminated! Suitor 2 will be eliminated! Suitor 7 will be Suflor WiLL Suitor 11 will be Sultor it will be eliminated eliminated! Sultor Suitor to will be eliminated! 16 will be eliminated! Sultor I will be eliminated! Suitor 1 will be eliminated! eliminated! Suitor 8 will be Sultor Suitor eliminated: 14 will be eliminated! Sultor will be eliminated Suitor 4 will be eliminated! 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 17. Check final list is correct... eliminated: eliminated!
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!
In an ancient land, the beautiful princess Eve had many suitors. She decided on the following procedure to determine which suitor she would marry. First, all of the suitors would be lined up one after the other and assigned
numbers. The first suitor would be number 1, the second number 2, and so on up to the last suitor, number n. Starting at the first suitor she would then count three suitors down the line (because of the three letters in her
name) and the third suitor would be eliminated from winning her hand and removed from the line. Eve would then continue, counting three more suitors, and eliminating every third suitor. When she reached the end of the
line she would continue counting from the beginning.
For example, if there were 6 suitors then the elimination process would proceed as follows:
Suitors: 1 2 3 4 5 6
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").
To easily debug your code, you should work on Visual Studio. Use the files available in the doubly-linked list chapter and create a list that stores integers from 1 to n (the number of suitors). Once it is working, you can paste
your code in CodeCheck.
This tool was successfully loaded in a new browser window. Reload the page to access the tool again.
Transcribed Image Text: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! In an ancient land, the beautiful princess Eve had many suitors. She decided on the following procedure to determine which suitor she would marry. First, all of the suitors would be lined up one after the other and assigned numbers. The first suitor would be number 1, the second number 2, and so on up to the last suitor, number n. Starting at the first suitor she would then count three suitors down the line (because of the three letters in her name) and the third suitor would be eliminated from winning her hand and removed from the line. Eve would then continue, counting three more suitors, and eliminating every third suitor. When she reached the end of the line she would continue counting from the beginning. For example, if there were 6 suitors then the elimination process would proceed as follows: Suitors: 1 2 3 4 5 6 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"). To easily debug your code, you should work on Visual Studio. Use the files available in the doubly-linked list chapter and create a list that stores integers from 1 to n (the number of suitors). Once it is working, you can paste your code in CodeCheck. This tool was successfully loaded in a new browser window. Reload the page to access the tool again.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education