Each element is colored either red, white, or blue. Write a program to permute the elements so

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

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: