[69,81,30,38,9,2,47,61,32,79]
- Selection Sort Wiki
- Insertion Sort Wiki
- Bubble Sort Wiki
- Quick Sort Wiki
It tries to find the smallest number and put it at the front.
def selectionsort(list)
list.size.times do |start|
min = start
start.upto(list.size-1) do |i|
min = i if list[i] < list[min]
end
list[start], list[min] = list[min], list[start]
end
list
end
It goes through the whole sequence, in order to compare the two elements next to each other. Biggest number would go to the end of sequence first.
- Your time