Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help in C++. I encountered those errors on CodeCheck. A few requirements: only use void DoublyList::selectSuitor(), don't forget to update count, don't forget to

image text in transcribedimage text in transcribedimage text in transcribed

Please help in C++. I encountered those errors on CodeCheck. A few requirements: only use void DoublyList::selectSuitor(), don't forget to update count, don't forget to delete the node. I can only use getNext(), getPrev() so please be specific... Thank you so much and I hope you have a great day.

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 17. Running Main.cpp Error: Functions.cpp: In member function 'void DoublyList::selectSuitor()': Functions.cpp:12:23: error: lvalue required as left operand of assignment 12 | last->getNext ()= first; Functions.cpp:13:24: error: lvalue required as left operand of assignment 13 | first->getPrev ()= last; Functions.cpp:29:27: error: lvalue required as left operand of assignment 29 prev->getNext ()= next; Functions.cpp:30:27: error: lvalue required as left operand of assignment 30 next->getPrev ()= prev

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

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students also viewed these Databases questions