Advertisement
Guest User

Untitled

a guest
May 24th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. list = []
  2. for i in range(1,10):
  3. list.append(random.randint(1,10))
  4.  
  5.  
  6.  
  7. def bubble_sort(list):
  8. len_list = len(list)
  9.  
  10.  
  11. for start_index in range(len_list-1):
  12.  
  13.  
  14.  
  15.  
  16. for index in range(1,len_list -i):
  17.  
  18.  
  19. # 큰수는 뒤로 밀려있고 이미 정렬이 되었으니, 앞의 순서들만 조정해주면된다.
  20. # ex) start_index = 5
  21.  
  22.  
  23.  
  24. if list[index-1] > list[index]
  25. # 만약 앞의 값이 > 뒤의값보다 크면,
  26. list[index-1],list[index] = list[index],list[index-1]
  27. # 앞의값과 뒤의값을 바꾼다.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement