Question: Suppose you have an array S of n elements where each element is labeled with either RED or BLUE. Arrange the elements so that all
Suppose you have an array S of n elements where each element is labeled with either RED or BLUE. Arrange the elements so that all the RED elements come before all the BLU elements. The only operations permitted are getColor(S[i]) that reports the color of S[i] and Swap(S, i, j) that swaps S[i] amd S[j]. Define a linear time solution for this problem. Use an enumeration type with values RED, BLUE to denote the colors in your pseudocode.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
