codes for learning sort