Repeatedly finds the minimum element from the unsorted part and puts it at the beginning. Return the sorted array.