how to write selection sort code