Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def swap(list, a, b):
- #where argument 2 & 3 are list indices
- store = list[a]
- list[a] = list[b]
- list[b] = store
- return list
- def swap_sort(x):
- #loop over the position that's to be compared to the other positions
- #when we arrive at the last position, it should already be in its proper place
- for i in range(0, len(x)-1):
- #loop over the positions that are compared
- for k in range(i+1, len(x)):
- if x[i] > x[k]:
- swap(x, i, k)
- return x
- g = [9, 8, 13, 4, 2, 5]
- e = [5,6,45,678,345,2,3453,56,578,2342456,567567,5,2,1,1,1,45,7,]
- print swap_sort(g), swap_sort(e)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement