TADM2E 4.4

From Algorithm Wiki
Revision as of 00:54, 8 July 2016 by Hezhe88 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Any stable sort can solve this problem, using the color as the key: such as insertion sort, merge sort or bucket sort(below)

Bucket Sort Algorithm:

Create 3 buckets, one each for red, blue and yellow.
for each Pair P in the input
   append P.number to the bucket P.color

Output the data from the red, blue and yellow buckets.