MCPcopy Create free account
hub / github.com/geekcomputers/Python / selection_sort

Function selection_sort

Sorting Algorithms/selection_sort.py:1–12  ·  view source on GitHub ↗
(nums)

Source from the content-addressed store, hash-verified

1def selection_sort(nums):
2 # This value of i corresponds to how many values were sorted
3 for i in range(len(nums)):
4 # We assume that the first item of the unsorted segment is the smallest
5 lowest_value_index = i
6 # This loop iterates over the unsorted items
7 for j in range(i + 1, len(nums)):
8 if nums[j] < nums[lowest_value_index]:
9 lowest_value_index = j
10 # Swap values of the lowest unsorted element with the first unsorted
11 # element
12 nums[i], nums[lowest_value_index] = nums[lowest_value_index], nums[i]
13
14
15# Verify it works

Callers 1

selection_sort.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected