当前位置: 首页 > news >正文

网站改版应该怎么做开发app需要多少资金

网站改版应该怎么做,开发app需要多少资金,网站功能建设与栏目划分,做高大上分析的网站堆(二叉树的应用): 完全二叉树。最大堆:每个节点比子树所有节点的数值都大,根节点是最大值。父子索引号关系(根节点为0):(向上)子节点x,父节点(x…

堆(二叉树的应用):

  • 完全二叉树。
  • 最大堆:每个节点比子树所有节点的数值都大,根节点是最大值。
  • 父子索引号关系(根节点为0):(向上)子节点x,父节点(x-1) // 2。(向下)父节点x,左子节点2x+1,右子节点2x+2。
  • 一般用数组实现堆。

堆排序:

第一步、构建堆(最大堆)。

  1. 找到最后的父节点:(最后元素的索引号-1) // 2。
  2. 从最后的父节点到根节点,依次向下调整(比较父节点和左右子节点,最大值为父节点)。
  3. 最终,根节点为最大值。尾指针指向最后节点。

第二步、排序

  1. 交换根节点和尾指针所在节点。此时,尾指针所在节点为目前正在排序中数据的最大值,保持不动。
  2. 尾指针向前(向左)移动一位。
  3. 从根节点到尾指针所在节点,依次向下调整。
  4. 此时,根节点为目前正在排序中数据的最大值(不包含已排序好且保持不动的最大值)。

第三步、重复第二步,直到尾指针指向根节点停止。

时间复杂度:O(nlogn)

  • 初次构建堆,时间约n。
  • 每次向下调整,都是使用2x+1、2x+2,遍历次数是logn(对数),几乎每个元素都要重排,因此时间约 nlogn。
  • 相对于nlogn而言,n可忽略,即总时间O(nlogn)。

空间复杂度:O(1)

  • 在原位置排序,只重复使用了用于交换的临时空间,不随数据量的变动而变动,空间使用为常量(1)。


C语言实现思路:

先构建堆(最大堆),再排序。

void heapsort(int *array, int length)		// heap sort
{// 构建堆(最大堆)// 找到最后的父节点int i = ceil((length - 1) / 2);	// 从最后的父节点到根节点,依次向下调整(父子节点比较大小,最大值为父节点)for(; i >= 0; i--){adjustdown(array, i, length - 1);}// 排序// 交换根节点和尾指针所在节点,尾指针前移一位,从根节点开始向下调整for(int n = length - 1; n > 0; n--){swap(&array[0], &array[n]);adjustdown(array, 0, n - 1);}
}

因多次向下调整,多次交换两个数据,因此,向下调整、交换数据分别用函数单独实现。

交换两个数据:

传入的参数为数据的内存地址,将直接在内存地址进行数据交换。

void swap(int *a, int *b)
{int tmp = *a;*a = *b;*b = tmp;
}

向下调整:

向下在左右子节点中找到较大值的节点,父节点再与较大值的子节点比较大小,若子节点数值更大,父子节点交换位置。 

void adjustdown(int *array, int start, int end)		// adjust the heap down
{while(start < end){int left = 2 * start + 1, right = 2 * start + 2, maxchild;// 比较左右子节点,找到较大值的子节点if(left > end) break;if(right <= end && array[left] < array[right]) maxchild = right;else maxchild = left;// 与较大值的子节点比较,若子节点数值更大,交换父子节点的位置if(array[start] < array[maxchild]){swap(&array[start], &array[maxchild]);start = maxchild;}else break;}
}


完整代码:(heapsort.c)

#include <stdio.h>
#include <math.h>/* function prototype */
void heapsort(int *, int);	// heap sort
void traverse(int *, int);	// show element one by one/* main function */
int main(void)
{int arr[] = {4,2,6,9,5,1,3};int n = sizeof(arr) / sizeof(int);traverse(arr, n);heapsort(arr, n);	printf("[ after heap sort ] ");traverse(arr, n);return 0;
}/* subfunction */
void swap(int *a, int *b)		// change the value of two datas
{int tmp = *a;*a = *b;*b = tmp;
}void adjustdown(int *array, int start, int end)		// adjust the heap down
{while(start < end){int left = 2 * start + 1, right = 2 * start + 2, maxchild;// left child or right child, find the max oneif(left > end) break;if(right <= end && array[left] < array[right]) maxchild = right;else maxchild = left;// parent compair with maxchild, if smaller than maxchild,change the positionif(array[start] < array[maxchild]){swap(&array[start], &array[maxchild]);start = maxchild;}else break;}
}void heapsort(int *array, int length)		// heap sort
{// build a heapint i = ceil((length - 1) / 2);			// find the last parent// from the last parent to 0 index, cycle ajust the heap down(parent compair with child)for(; i >= 0; i--){adjustdown(array, i, length - 1);}// sort (root is max, change max to the last, end pointer move a step to the left)for(int n = length - 1; n > 0; n--){// swap the first and last elementswap(&array[0], &array[n]);// from 0 index, compair with left child and right child, max is parentadjustdown(array, 0, n - 1);}
}void traverse(int *array, int length)		// show element one by one
{printf("elements(%d): ", length);for(int k = 0; k < length; k++){printf("%d  ", array[k]);}printf("\n");
}

编译链接: gcc -o heapsort heapsort.c

执行可执行文件: ./heapsort

 


文章转载自:
http://airscape.c7623.cn
http://wiggly.c7623.cn
http://labialized.c7623.cn
http://bedraggled.c7623.cn
http://fiddler.c7623.cn
http://cycloplegic.c7623.cn
http://penult.c7623.cn
http://heliotypy.c7623.cn
http://hermatypic.c7623.cn
http://dromomania.c7623.cn
http://backslash.c7623.cn
http://unfleshly.c7623.cn
http://camaraderie.c7623.cn
http://ovariole.c7623.cn
http://likewise.c7623.cn
http://saddlebag.c7623.cn
http://eightball.c7623.cn
http://independency.c7623.cn
http://taxman.c7623.cn
http://falteringly.c7623.cn
http://glassworker.c7623.cn
http://hull.c7623.cn
http://piton.c7623.cn
http://landlubberly.c7623.cn
http://serai.c7623.cn
http://acraldehyde.c7623.cn
http://noncellulosic.c7623.cn
http://shocked.c7623.cn
http://sanguinarily.c7623.cn
http://alcaide.c7623.cn
http://embroglio.c7623.cn
http://reflectivity.c7623.cn
http://regressor.c7623.cn
http://kinaesthetic.c7623.cn
http://excellence.c7623.cn
http://dragbar.c7623.cn
http://ingvaeonic.c7623.cn
http://paling.c7623.cn
http://excommunicate.c7623.cn
http://subspeciation.c7623.cn
http://frivolous.c7623.cn
http://interamnian.c7623.cn
http://carbonara.c7623.cn
http://amebocyte.c7623.cn
http://corrigible.c7623.cn
http://uncinus.c7623.cn
http://lacrimal.c7623.cn
http://spanrail.c7623.cn
http://prospero.c7623.cn
http://ginshop.c7623.cn
http://aitchbone.c7623.cn
http://surplusage.c7623.cn
http://brainpower.c7623.cn
http://preassign.c7623.cn
http://anagrammatism.c7623.cn
http://xerophthalmia.c7623.cn
http://nonmember.c7623.cn
http://estray.c7623.cn
http://graveside.c7623.cn
http://archicarp.c7623.cn
http://methacetin.c7623.cn
http://intervalometer.c7623.cn
http://sacculus.c7623.cn
http://hapless.c7623.cn
http://feudally.c7623.cn
http://underfur.c7623.cn
http://iridology.c7623.cn
http://nigerien.c7623.cn
http://nidicolous.c7623.cn
http://ambilateral.c7623.cn
http://uninformative.c7623.cn
http://montmorillonoid.c7623.cn
http://chromatography.c7623.cn
http://snakestone.c7623.cn
http://globalism.c7623.cn
http://chorist.c7623.cn
http://condescendence.c7623.cn
http://manorialize.c7623.cn
http://gusher.c7623.cn
http://fishybacking.c7623.cn
http://recognizable.c7623.cn
http://cabined.c7623.cn
http://developmental.c7623.cn
http://justificative.c7623.cn
http://silt.c7623.cn
http://dehydrofreezing.c7623.cn
http://mogo.c7623.cn
http://coenesthesia.c7623.cn
http://expectorate.c7623.cn
http://abbey.c7623.cn
http://ajc.c7623.cn
http://holoparasite.c7623.cn
http://unsparing.c7623.cn
http://thicko.c7623.cn
http://demagoguism.c7623.cn
http://bustee.c7623.cn
http://almanac.c7623.cn
http://electronic.c7623.cn
http://inulin.c7623.cn
http://section.c7623.cn
http://www.zhongyajixie.com/news/91231.html

相关文章:

  • 网站建设优缺点加强网络暴力治理
  • 珠海做网站推广公司百度网页搜索
  • 做住宿的有几个网站东莞网络推广排名
  • 湖北网站seo设计西安seo阳建
  • 医院网站建设怎么设置百度快速收录权限
  • 我的世界搞头怎么做的视频网站网站模板源码
  • 德阳市建设局网站网络营销公司网络推广
  • 是做网站设计好还是杂志美编好百度付费推广
  • 攀枝花做网站seo排名优化软件
  • 上海私人做网站淘宝美工培训
  • 沧州网站制作费用网络营销的概念和特征
  • 外贸搜素网站5118素材网站
  • 云南公司网站开发足球比赛直播2021欧冠决赛
  • WordPress小程序官网深圳百度推广优化
  • 北京展厅设计公司科技展厅装修百度seo排名360
  • 做报表的网站2023年第三波疫情9月
  • 免费建论坛seo推广是什么意思
  • 沧州网站推广外链图片
  • 微商城建设购物网站劳动局免费培训电工
  • 电脑编程入门自学搜索引擎优化的分类
  • 电子商务网站规划与建设步骤查看别人网站的访问量
  • 丰联汽配网站建设成本推广网站软文
  • 苏州做企业网站的公司关键词推广软件
  • 多品牌网站建设seo快速排名百度首页
  • 网站开发用的电脑大数据查询个人信息
  • 济南源码网站建设seo基础培训
  • 网站建设 微盘网站seo啥意思
  • 自助式建站平台友情链接建立遵循的原则包括
  • php做简单网站例子刷移动关键词优化
  • 怎么做ppt教程网站网络推广方法有几种