python---选择排序,, 感觉没有简单多少
python---选择排序,, 感觉没有简单多少
感觉没有简单多少。
# coding = utf-8# 选择排序def selection_sort(a_list): loop_count = 0 swap_count = 0 for fill_slot in range(0, len(a_list)): loop_count += 1 pos_of_min = fill_slot for location in range(fill_slot+1, len(a_list)): loop_count += 1 if a_list[pos_of_min] > a_list[location]: pos_of_min = location swap_count += 1 a_list[fill_slot], a_list[pos_of_min] = a_list[pos_of_min], a_list[fill_slot] print(a_list) print(‘======== selection_sort loop_count========‘, loop_count) print(‘========selection_sort swap_count=========‘, swap_count)my_list = [4, 5, 7, 2, 9, 7, 9, 54, 765, 45, 9876, 34, 12343, 36]selection_sort(my_list)print(my_list)
C:\Users\Sahara\.virtualenvs\test\Scripts\python.exe C:/Users/Sahara/PycharmProjects/test/python_search.py[2, 5, 7, 4, 9, 7, 9, 54, 765, 45, 9876, 34, 12343, 36][2, 4, 7, 5, 9, 7, 9, 54, 765, 45, 9876, 34, 12343, 36][2, 4, 5, 7, 9, 7, 9, 54, 765, 45, 9876, 34, 12343, 36][2, 4, 5, 7, 9, 7, 9, 54, 765, 45, 9876, 34, 12343, 36][2, 4, 5, 7, 7, 9, 9, 54, 765, 45, 9876, 34, 12343, 36][2, 4, 5, 7, 7, 9, 9, 54, 765, 45, 9876, 34, 12343, 36][2, 4, 5, 7, 7, 9, 9, 54, 765, 45, 9876, 34, 12343, 36][2, 4, 5, 7, 7, 9, 9, 34, 765, 45, 9876, 54, 12343, 36][2, 4, 5, 7, 7, 9, 9, 34, 36, 45, 9876, 54, 12343, 765][2, 4, 5, 7, 7, 9, 9, 34, 36, 45, 9876, 54, 12343, 765][2, 4, 5, 7, 7, 9, 9, 34, 36, 45, 54, 9876, 12343, 765][2, 4, 5, 7, 7, 9, 9, 34, 36, 45, 54, 765, 12343, 9876][2, 4, 5, 7, 7, 9, 9, 34, 36, 45, 54, 765, 9876, 12343][2, 4, 5, 7, 7, 9, 9, 34, 36, 45, 54, 765, 9876, 12343]======== selection_sort loop_count======== 105========selection_sort swap_count========= 14[2, 4, 5, 7, 7, 9, 9, 34, 36, 45, 54, 765, 9876, 12343]Process finished with exit code 0
python---选择排序
相关内容
- Python的基础教程,比PHP、GO等前景好的一门开发语言!
- pip离线安装python包,,1 首先在一台能上网
- python3 安装pip提示没有distutils.util模块错误的解决,,环
- python中Keras下载mnist数据集,,python中Ker
- python—用for循环、while循环和一句话打印九九乘法表,
- 关于linux系统下CRONTAB运行python脚本不生效,,
- 利用python 获取网址中的href(基于python 3.6),,import url
- python中实现可迭代对象的方法,,当对元组,列表,字典
- python批量ssh/telnet远程登录设备,,闲暇用python写
- python 生成随机红包,,假设红包金额为mon
评论关闭