• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > python选择排序算法实例总结

python选择排序算法实例总结

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了python算法实例,python多线程实例,python实例,python程序实例,python脚本实例等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文实例总结了python选择排序算法。分享给大家供大家参考。具体如下:

代码1:

def ssort(V):
#V is the list to be sorted 
 j = 0
 #j is the "current" ordered position, starting with the first one in the list 
 while j != len(V):
 #this is the replacing that ends when it reaches the end of the list 
   for i in range(j, len(V)):
   #here it replaces the minor value that it finds with j position 
     if V[i] < V[j]:
     #but it does it for every value minor than position j 
       V[j],V[i] = V[i],V[j] 
   j = j+1
   #and here's the addiction that limits the verification to only the next values 
 return V 

</div>

代码2:

def selection_sort(list): 
  l=list[:]
  # create a copy of the list 
  sorted=[]
  # this new list will hold the results 
  while len(l):
  # while there are elements to sort... 
    lowest=l[0]
    # create a variable to identify lowest 
    for x in l:
    # and check every item in the list... 
      if x<lowest:
      # to see if it might be lower. 
        lowest=x 
    sorted.append(lowest)
    # add the lowest one to the new list 
    l.remove(lowest)
    # and delete it from the old one 
  return sorted
</div>

代码3

a=input("Enter the length of the list :")
# too ask the user length of the list 
l=[]
# take a emty list 
for g in range (a):
# for append the values from user 
  b=input("Enter the element :")
  # to ask the user to give list values 
  l.append(b)
  # to append a values in a empty list l 
print "The given eliments list is",l 
for i in range (len(l)):
# to repeat the loop take length of l 
  index=i
  # to store the values i in string index 
  num=l[i]
  # to take first value in list and store in num 
  for j in range(i+1,len(l)):
  # to find out the small value in a list read all values 
    if num>l[j]:
    # to compare two values which store in num and list 
      index=j
      # to store the small value of the loop j in index 
      num=l[j]
      # to store small charecter are value in num 
  tem=l[i]
  # to swap the list take the temparary list stor list vlaues 
  l[i]=l[index]
  # to take first value as another 
  l[index]=tem 
print "After the swping the list by selection sort is",l

</div>

希望本文所述对大家的Python程序设计有所帮助。

</div>

您可能想查找下面的文章:

  • python 实现红包随机生成算法的简单实例
  • python 实现红包随机生成算法的简单实例
  • Python图算法实例分析
  • python插入排序算法实例分析
  • python选择排序算法实例总结
  • Python实现二分查找算法实例
  • Python实现二分查找算法实例
  • Python二分法搜索算法实例分析
  • Python最长公共子串算法实例
  • Python实现的几个常用排序算法实例

相关文章

  • 详解Python中的Descriptor描述符类
  • Python创建系统目录的方法
  • tensorflow estimator 使用hook实现finetune方式
  • python 实现自动远程登陆scp文件实例代码
  • centos6.7安装python2.7.11的具体方法
  • Python多线程实例教程
  • Phantomjs抓取渲染JS后的网页(Python代码)
  • Python实现将数据库一键导出为Excel表格的实例
  • Python实现将DOC文档转换为PDF的方法
  • python根据经纬度计算距离示例

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • python django集成cas验证系统
    • 利用Python画ROC曲线和AUC值计算
    • Python实现的数据结构与算法之双端队列详解
    • Python实现二维有序数组查找的方法
    • 使用Python操作MySQL的一些基本方法
    • Python基本数据类型详细介绍
    • Python实现将绝对URL替换成相对URL的方法
    • python实现class对象转换成json/字典的方法
    • python引用DLL文件的方法
    • Python随机生成信用卡卡号的实现方法

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有