Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- list = []
- for i in range(1,10):
- list.append(random.randint(1,10))
- def bubble_sort(list):
- len_list = len(list)
- for start_index in range(len_list-1):
- for index in range(1,len_list -i):
- # 큰수는 뒤로 밀려있고 이미 정렬이 되었으니, 앞의 순서들만 조정해주면된다.
- # ex) start_index = 5
- if list[index-1] > list[index]
- # 만약 앞의 값이 > 뒤의값보다 크면,
- list[index-1],list[index] = list[index],list[index-1]
- # 앞의값과 뒤의값을 바꾼다.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement