Question: Each element is colored either red, white, or blue. Write a program to permute the elements so that all the red elements are first and

Each element is colored either red, white, or blue. Write a program to permute the elements so that all the red elements are first and all the blue ones last. The color of an element may be tested with Boolean expressions red(b[i]), white(b[i]) and blue(b[i]) which return the obvious values. The number of tests should be kept to a minimum. The only way to permute array elements is to swap two of them; the program should make at most n swaps. You may just use one process, i.e., no send or receive command is needed.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Systems Analysis And Design Questions!