Implemented the selection sort.