Implement counting sort