Sorts elements by repeatedly selecting the required value.