# -*- coding:gb2312 -*-
'''
Created on 2010-7-29
@author: http://g-content.appspot.com
'''
#希尔排序
#定义一个数组
#lst = [81, 94, 11, 96, 12, 24, 17, 95, 28, 58, 41, 75, 15]
lst = [81, 94, 11, 96, 12, 35, 17, 95, 28, 58, 41, 75, 15]
ord = [5, 3, 1]
for i in ord:
#按当前序列值进行循环分组排序
for o in range(len(lst)):
#得到分组序号
grp = range(o, len(lst), i);
if len(grp) <= 1:
break;
#对当前分组进行插入排序
for c in range(1, len(grp)):
#获得当前分组最后一个值
last = lst[grp[c]]
#插入排序第n趟序列
n = range(1, c + 1)
#从右到左比较
n.reverse()
for f in n:
'''
由于n是针对分组的序列,所以实际值是lst[grp[f]]
'''
if lst[grp[f]] < lst[grp[f - 1]]:
lst[grp[f]] = lst[grp[f-1]]
lst[grp[f-1]] = last
print '第',i,'排序是',lst
分享到:
相关推荐
Python排序算法详解 Python排序算法——冒泡排序 Python排序算法——插入排序 Python排序算法——选择排序 Python排序算法——快速排序 Python排序算法——归并排序
python 智能算法——简单例子蚁群算法.py
python 智能算法——粒子群算法简单例子
python 智能算法——简单例子免疫算法.py
该程序包含7大排序算法: # sort.bubbleSort() #冒泡排序 # sort.shellSort() #希尔排序 # sort.insertionSort() #插入排序 # sort.Selectionsort1() #选择排序 # sort.heapSort() #堆排序 # sort.countSort() ...
数据结构与算法 Python语言描述-裘宗燕 高清带目录 详细讲述线性表 、字符串、栈和队列、二叉树和树、图、字典和集合、排序等
python 智能算法——简单例子遗传2.py
基于python-2.7实现的K-Shell节点排序算法,算法结果输出每个节点K值。
算法与数据结构——快速排序
算法设计与分析课程——冒泡排序结果
python 智能算法——简单例子人工捕鱼.py
计算机系的教材,算法导论————————————————————————————————
PTA_python3_jmu-python-凯撒密码加密算法(csdn)————程序
数学建模30个常用算法(Python)数学建模30个常用算法(Python)数学建模30个常用算法(Python)数学建模30个常用算法(Python)数学建模30个常用算法(Python)数学建模30个常用算法(Python)数学建模30个常用算法...
算法之NlogN排序算法(csdn)————程序
机器人学、机器视觉与控制——MATLAB算法基础.pdf
python 智能算法——简单例子模拟退火.py
非支配排序遗传算法(NSGA-II) 的实现,一种Python 中 的多目标优化算法_python_Jupyter _代码_下载
基于Python语言的“算法分析”课程设计——以动态规划算法为例.pdf
python 2048游戏核心算法(csdn)————程序