Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi, I need help with the function that is highlighted in yellow. In the function

ID: 3751793 • Letter: H

Question

Hi, I need help with the function that is highlighted in yellow. In the function, I want to arrange the disks. For example, if I have 4 dark disks and 5 light disks, I want the 5 light disks to be placed on the left side and 4 dark disks on the right side.

I don't know what to implement in order for this to happen. Please provide suggestions/tips.

I provided the hpp and cpp files below. Let me know if you need more info, Thanks.

hpp file

CPP file

class sorted_disks private: disk_state _after; unsigned _swap_count; disk_state _before; public: sorted_disks(const disk_state& after, unsigned swap_count) : _after(after), _swap_count (swap_count) sorted_disks(disk_state&& after, unsigned swap_count) : _after(after), _swap_count (swap_count) const disk_state& after) const f return after: unsigned swap_count() const { return swap count: // Algorithm that sorts disks using the left-to-right algorithm sorted disks sort_left to_right(const disk state& before) // TODO: Write code for this function, including rewriting the return / statement, and then delete these comments. return sorted-disks(before, 0);

Explanation / Answer

According to my understanding if disks are to be arranged in order of their specification [for example: i.e.light_disks(left side) & dark_disks(right side)],

For the explanation :

light_disks represented as 1,2,3

dark_disks represented as 97,98,99

STEP 1: sort the disks according to the specification.

STEP 2:Perform left rotation on the range of disks.(use of rotate function)

Specifically, rotate swaps the elements in the range [first, last) in such a way that the element n_first becomes the first element of the new range and n_first - 1 becomes the last element.

A precondition of this function is that [first, n_first) and [n_first, last) are valid ranges.

Parameters

first - the beginning of the originsl range

n-first - the element that should appear at the beginnin g of the rotated range

last - the end of the original range

Return Value:

the iterator equal to first + (last - n_first)

(if light and dark disks are assumed as numbers bubble sort can do it)

[Please let me know if I need to be more clear and precise.

Request to please specify the specification of the disk I assumed it as number(i.e. acc to weight of the disk)]

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote