Advertisement
harsh_jec

selection_sort(round_2 codevita)

Aug 27th, 2015
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. def sort_selection(my_list):
  2.  
  3. for pos_upper in xrange( len(my_list)-1, 0, -1):
  4. max_pos = 0
  5. for i in xrange(1, pos_upper + 1):
  6. if(my_list[i] > my_list[max_pos]):
  7. max_pos = i
  8. #print "resetting max_pos = " + str(max_pos)
  9.  
  10. my_list[pos_upper], my_list[max_pos] = my_list[max_pos], my_list[pos_upper]
  11. #print "pos_upper: " + str(pos_upper) + " max_pos: " + str(max_pos) + " my_list: " + str(my_list)
  12.  
  13. return my_list
  14.  
  15. m_list=["cab","abc","bac"]
  16. sort_selection(m_list)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement