Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone solve this problem using c++. I'm totally stuck. A robot has the task of sorting a number of colored pebbles contained in a

Can someone solve this problem using c++. I'm totally stuck. image text in transcribed
A robot has the task of sorting a number of colored pebbles contained in a row of buckets. The buckets are arranged in front of the robot and each contains exactly one pebble colored either red. white or blue. The robot is equipped with two arms, on the end of each of which is an eye. Using its eye, the robot can determine color(i), the color of the pebble in the ith bucket, and using its arms the robot can perform the action swap(i, j) to swap the pebbles in buckets i and j. The robot is required to sort the pebbles into three segments - the first containing all red pebbles, the second containing all white pebbles, and the third containing all blue pebbles. Using a char array to simulate the buckets, and chars r, w, and b for the three colors of marbles, write a program to control the robot's sorting of the pebbles. Additional Requirements: (1) note that the robot does not have extra buckets -- accordingly, your program may not use any extra arrays, and it may not use extra space in the array you set up to model the buckets (because there is none!); (2) you may not change the color of any marble: all your program can do to the marbles is to swap them between buckets. Suggestion: first, write down pseudo-code for main in terms of functions; second, set up your input and output functions; third, write a function MoveRedToLeft which moves all r's to the left of the array (without changing the numbers of r's, w's or b's) -auxiliary functions, such as Swap, will be needed; fourth, adapt MoveRedToLeft to write another function, MoveWhiteToLeft which moves all w's to the left of any b in the s/b section created by MoveRedToLeft. Be sure to make good use of reference parameters - perhaps the only global needed is DisplayMax (the maximum number of characters to be displayed on one line), and this should be const

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

Database And Transaction Processing

Authors: Philip M. Lewis, Arthur Bernstein, Michael Kifer

1st Edition

0201708728, 978-0201708721

More Books

Students also viewed these Databases questions

Question

KEY QUESTION Refer to the table in question

Answered: 1 week ago