Skip to content

Instantly share code, notes, and snippets.

@cip123
Created December 7, 2015 20:19
Show Gist options
  • Save cip123/17af9157e823a843c46b to your computer and use it in GitHub Desktop.
Save cip123/17af9157e823a843c46b to your computer and use it in GitHub Desktop.
selection-sort.py
numbers = [1, 5, 7, 2, 4, 3]
def swap(i, j):
t = numbers[i]
numbers[i] = numbers[j]
numbers[j] = t
size = len(numbers)
for i in range(0, size):
min = i
for j in range (i + 1, size):
if numbers[j] < numbers[min] : min = j
swap(i, min)
print numbers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment