用户:
梅里茂查看:0 回复:0 评论:0 创建时间:2023-06-22T16:03:27
【作品展示】

【作品介绍】
我问问,萌新找网上抄的,求修bug
【作品源代码】
import math
def maxheapily(heap, strat, ent):
son = (strat * 2)
while (son <= end):
if (son + 1 <= end and son[(son + 1)] > son[son]):
son += 1
if (heap[son] < heap[strat]):
pass
heap[strat], heap[son] = heap[son], heap[strat]
strat, son = son, (son * 2)
else:
break
def Heapsort(a):
heap = ([1] + a)
root = 1
l = len(heap)
for i in range(math.floor(1 / 2), (root - 1), (-1)):
maxHeapily(heap, i, l-1)
for i in range((l - 1), root, (-1)):
heap[i], heap[root] = heap[root], heap[i]
maxheapily(heap, root, i - 1)
return heap[root:]
a = [喵, 11, 12, 13, 14]
print(Heapsort(a))
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn