27. python_027.py(bubblesort) |
|||||
---|---|---|---|---|---|
작성자 | 수안보중 | 등록일 | 20.06.22 | 조회수 | 44 |
#python_027.py(bubblesort) data_total = [73, 36, 86, 9, 160] repeat_count = 0 changed = True while changed: changed = False repeat_count += 1 for index in range(len(data_total) - repeat_count): if data_total[index] > data_total[index+1]: data_total[index], data_total[index+1] = data_total[index+1], data_total[index] changed = True print(data_total) <결과> [36, 73, 86, 9, 160] [36, 73, 9, 86, 160] [36, 9, 73, 86, 160] [9, 36, 73, 86, 160]
|
이전글 | 28. #python_028.py(quicksort) |
---|---|
다음글 | 26. python_026.py(파일저장, 읽어오기) |