码迷,mamicode.com
首页 > 编程语言 > 详细

堆排序

时间:2020-06-12 01:13:05      阅读:59      评论:0      收藏:0      [点我收藏+]

标签:执行   size   sub   color   思想   堆排序   remove   ++   输出   

堆排序

堆排序的思想是先调用堆的inset方法,再调用堆的remove方法输出。


实现

for (i = 0; i < size; i++)
    heap.insert(array[i]);
for (i = 0; i < size; i++)
    array[i] = heap.remove();

效率

堆的insert、remove都是log2N;且insert、remove都要执行n次,所以整体的效率是2*N*log2N,O(N*logN)。

堆排序

标签:执行   size   sub   color   思想   堆排序   remove   ++   输出   

原文地址:https://www.cnblogs.com/Mike_Chang/p/13096887.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!