Advertisement
Guest User

Untitled

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