What is wrong with my sorting logic?

What is wrong with my sorting logic?