Devise an algorithm to sort playing cards. The rules are as follows: