How is counting sort a stable sort?

Posted by eSKay on Stack Overflow See other posts from Stack Overflow or by eSKay
Published on 2010-04-03T18:19:07Z Indexed on 2010/04/03 18:23 UTC
Read the original article Hit count: 708

Suppose my input is (a,b and c to distinguish between equal keys)

1 6a 8 3 6b 0 6c 4

My counting sort will save as (discarding the a,b and c info!!)

0(1) 1(1) 3(1) 4(1) 6(3) 8(1)

which will give me the result

0 1 3 4 6 6 6 8

So, how is this stable sort? I am not sure how it is "maintaining the relative order of records with equal keys."

Please explain.

© Stack Overflow or respective owner

Related posts about sorting

Related posts about counting-sort