Algorithm sorting code