Question #73550

3. Assume that we are given n pairs of items as input, where the first item is a number and the second item is one of three colors (red, blue, or yellow). Further assume that the items are sorted by number. Give an algorithm to sort the items by color (all reds before all blues before all yellows) such that the numbers for identical colors stay sorted.

For example: (1,blue), (3,red), (4,blue), (6,yellow), (9,red) should become (3,red),

(9,red), (1,blue), (4,blue), (6,yellow).

For example: (1,blue), (3,red), (4,blue), (6,yellow), (9,red) should become (3,red),

(9,red), (1,blue), (4,blue), (6,yellow).

Expert's answer

Dear Atif Haroon, your question requires a lot of work, which neither of our experts is ready to perform for free. We advise you to convert it to a fully qualified order and we will try to help you. Please click the link below to proceed: **Submit order**

## Comments

## Leave a comment