you need to go through certain sorting algos:

Click here