网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

堆排序的基本实现

void AdjustHeap(int *a, int size,int root)//建最大堆

创新互联公司一直通过网站建设和网站营销帮助企业获得更多客户资源。 以"深度挖掘,量身打造,注重实效"的一站式服务,以成都网站设计、网站制作、移动互联产品、成都全网营销推广服务为核心业务。10年网站制作的经验,使用新网站建设技术,全新开发出的标准网站,不但价格便宜而且实用、灵活,特别适合中小公司网站制作。网站管理系统简单易用,维护方便,您可以完全操作网站资料,是中小公司快速网站建设的选择。

{

if (a == NULL )

{

return;

}

int child = root*2+1;

while (child

{

if ((child + 1) < size && a[child] < a[child + 1])

{

++child;

}

if (a[root]

{

swap(a[child], a[root]);

}

root = child;

child = root * 2 + 1;

}

}

void Adjustdown(int *a, int size, int root)//向下调整,将堆顶的数据换到堆底后把长度减一;

{                            //再将堆顶数据向下比较,建成最大堆     

int child = root * 2 + 1;

while (child < size)

{

if ((child + 1) < size && a[child] < a[child + 1])

{

++child;

}

if (a[child] > a[root])

{

swap(a[child], a[root]);

}

root = child;

child = root * 2 + 1;

}

}

void HeapSort(int *a,int length)

{

if (a == NULL || length <= 0)

{

return;

}

for (int i = (length - 2) / 2; i >= 0; i--)

{

AdjustHeap(a, length, i);

}

for (int i = length - 1; i > 0; i--)

{

int tmp = a[0];

a[0] = a[i];

a[i] = tmp;

Adjustdown(a, i, 0);

}

}


本文标题:堆排序的基本实现
网页地址:http://bjjierui.cn/article/gihhhg.html

其他资讯