Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/139.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 按降序排列_Python 3.x - Fatal编程技术网

Python 3.x 按降序排列

Python 3.x 按降序排列,python-3.x,Python 3.x,因此,我的程序目前按升序排序,但我必须按降序排序。我想得到一些帮助,我应该改变什么,以便它按降序排序。请注意,不允许使用内置排序函数,例如排序(array,reverse=True) def外壳排序(数组): n=len(数组) 间隙=n//2 当间隙>0时: 对于范围内的i(间隙,n): 温度=数组[i] j=i 当j>=间隙和阵列[j-gap]

因此,我的程序目前按升序排序,但我必须按降序排序。我想得到一些帮助,我应该改变什么,以便它按降序排序。请注意,不允许使用内置排序函数,例如排序(array,reverse=True)

def外壳排序(数组):
n=len(数组)
间隙=n//2
当间隙>0时:
对于范围内的i(间隙,n):
温度=数组[i]
j=i
当j>=间隙和阵列[j-gap]
更改:

while  j >= gap and array[j - gap] > temp:
致:

将输出:

[8, 5, 4, 2, 1]
更改:

while  j >= gap and array[j - gap] > temp:
致:

将输出:

[8, 5, 4, 2, 1]
[8, 5, 4, 2, 1]