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

宁波做亚马逊网站网络营销理论包括哪些

宁波做亚马逊网站,网络营销理论包括哪些,网络广告文案范文,网上赚钱的软件堆的实现与堆排序及TopK问题的C语言代码 下面是详细的堆实现&#xff0c;包括向上调整、向下调整算法&#xff0c;以及堆排序和解决TopK问题的完整C语言示例代码。 1. 堆的实现 首先&#xff0c;定义堆的数据结构&#xff1a; #include <stdio.h> #include <stdli…

堆的实现与堆排序及TopK问题的C语言代码

下面是详细的堆实现,包括向上调整、向下调整算法,以及堆排序和解决TopK问题的完整C语言示例代码。

1. 堆的实现

首先,定义堆的数据结构:

#include <stdio.h>
#include <stdlib.h>#define MAX_HEAP_SIZE 100typedef struct {int data[MAX_HEAP_SIZE];int size;
} Heap;Heap* createHeap() {Heap* heap = (Heap*)malloc(sizeof(Heap));heap->size = 0;return heap;
}
2. 向上调整算法
void heapifyUp(Heap* heap, int index) {int parentIndex = (index - 1) / 2;if (index > 0 && heap->data[index] > heap->data[parentIndex]) {// 交换当前节点和父节点int temp = heap->data[index];heap->data[index] = heap->data[parentIndex];heap->data[parentIndex] = temp;// 递归向上调整heapifyUp(heap, parentIndex);}
}
3. 向下调整算法
void heapifyDown(Heap* heap, int index) {int largest = index;int leftChild = 2 * index + 1;int rightChild = 2 * index + 2;if (leftChild < heap->size && heap->data[leftChild] > heap->data[largest]) {largest = leftChild;}if (rightChild < heap->size && heap->data[rightChild] > heap->data[largest]) {largest = rightChild;}if (largest != index) {// 交换当前节点和最大子节点int temp = heap->data[index];heap->data[index] = heap->data[largest];heap->data[largest] = temp;// 递归向下调整heapifyDown(heap, largest);}
}
4. 插入元素到堆
void insertHeap(Heap* heap, int value) {if (heap->size >= MAX_HEAP_SIZE) {printf("Heap is full!\n");return;}heap->data[heap->size] = value;heap->size++;heapifyUp(heap, heap->size - 1);
}
5. 删除堆顶元素
int extractMax(Heap* heap) {if (heap->size <= 0) {printf("Heap is empty!\n");return -1;}int maxValue = heap->data[0];heap->data[0] = heap->data[heap->size - 1];heap->size--;heapifyDown(heap, 0);return maxValue;
}
6. 堆排序
void heapSort(int* array, int length) {Heap* heap = createHeap();for (int i = 0; i < length; i++) {insertHeap(heap, array[i]);}for (int i = length - 1; i >= 0; i--) {array[i] = extractMax(heap);}free(heap);
}
7. TopK问题

解决TopK问题,即找出数据流中前K大的元素,可以使用一个最小堆来实现。

void topK(int* array, int length, int k) {if (k <= 0 || k > length) {printf("Invalid value of K!\n");return;}Heap* heap = createHeap();for (int i = 0; i < k; i++) {insertHeap(heap, array[i]);}for (int i = k; i < length; i++) {if (array[i] > heap->data[0]) {heap->data[0] = array[i];heapifyDown(heap, 0);}}printf("Top %d elements: ", k);for (int i = 0; i < k; i++) {printf("%d ", extractMax(heap));}printf("\n");free(heap);
}
8. 测试代码
int main() {int array[] = {3, 2, 1, 5, 6, 4};int length = sizeof(array) / sizeof(array[0]);// 测试堆排序heapSort(array, length);printf("Sorted array: ");for (int i = 0; i < length; i++) {printf("%d ", array[i]);}printf("\n");// 测试TopK问题int k = 3;int array2[] = {3, 2, 1, 5, 6, 4};length = sizeof(array2) / sizeof(array2[0]);topK(array2, length, k);return 0;
}

解释

  1. 堆的实现:使用数组和一个结构体来表示堆,包含堆的数据和大小。
  2. 向上调整算法:在插入新元素后,通过比较当前节点和父节点的值来调整堆,确保堆的性质。
  3. 向下调整算法:在删除堆顶元素后,通过比较当前节点和子节点的值来调整堆,确保堆的性质。
  4. 堆排序:利用堆的插入和删除操作,将数组中的元素排序。
  5. TopK问题:使用最小堆找出数据流中前K大的元素。

通过这些步骤和代码实现,可以高效地进行堆操作、堆排序以及解决TopK问题。


文章转载自:
http://dinncomediae.tqpr.cn
http://dinncobaikal.tqpr.cn
http://dinncodobbie.tqpr.cn
http://dinncogoldie.tqpr.cn
http://dinncoturista.tqpr.cn
http://dinncopremeditate.tqpr.cn
http://dinncohorseless.tqpr.cn
http://dinncodopant.tqpr.cn
http://dinncoremoulade.tqpr.cn
http://dinncorhetoric.tqpr.cn
http://dinncotopstitch.tqpr.cn
http://dinncofrescoing.tqpr.cn
http://dinncokowait.tqpr.cn
http://dinncotetraparental.tqpr.cn
http://dinncoaw.tqpr.cn
http://dinncophospholipase.tqpr.cn
http://dinncosmaze.tqpr.cn
http://dinncoexedra.tqpr.cn
http://dinncoextrapyramidal.tqpr.cn
http://dinncohavurah.tqpr.cn
http://dinncobedge.tqpr.cn
http://dinncohibernacle.tqpr.cn
http://dinncoarid.tqpr.cn
http://dinncodouceur.tqpr.cn
http://dinncobrunizem.tqpr.cn
http://dinncomuhtar.tqpr.cn
http://dinncoshorefront.tqpr.cn
http://dinncoboondagger.tqpr.cn
http://dinncocurch.tqpr.cn
http://dinncotetrahymena.tqpr.cn
http://dinncoboysenberry.tqpr.cn
http://dinncocampanological.tqpr.cn
http://dinncoprocuratory.tqpr.cn
http://dinncothermojet.tqpr.cn
http://dinncofriseur.tqpr.cn
http://dinncosardar.tqpr.cn
http://dinncofarrier.tqpr.cn
http://dinncoshammas.tqpr.cn
http://dinncoscaler.tqpr.cn
http://dinncoatlatl.tqpr.cn
http://dinncocompositor.tqpr.cn
http://dinncoatherogenesis.tqpr.cn
http://dinncoballasting.tqpr.cn
http://dinncojupon.tqpr.cn
http://dinncoscottice.tqpr.cn
http://dinncobenevolently.tqpr.cn
http://dinncoprelusion.tqpr.cn
http://dinncosimpleness.tqpr.cn
http://dinncofracturation.tqpr.cn
http://dinncodianetic.tqpr.cn
http://dinncoherdwick.tqpr.cn
http://dinnconontoxic.tqpr.cn
http://dinncoworkload.tqpr.cn
http://dinncobankable.tqpr.cn
http://dinncobowsman.tqpr.cn
http://dinncomuzz.tqpr.cn
http://dinncotidemark.tqpr.cn
http://dinncopalpebral.tqpr.cn
http://dinncocapsular.tqpr.cn
http://dinncocookoff.tqpr.cn
http://dinncoundimmed.tqpr.cn
http://dinncorepellence.tqpr.cn
http://dinncotaittinger.tqpr.cn
http://dinncoitr.tqpr.cn
http://dinncoalga.tqpr.cn
http://dinncobeauty.tqpr.cn
http://dinncoclonally.tqpr.cn
http://dinncoseriousness.tqpr.cn
http://dinncoflameproof.tqpr.cn
http://dinncofeedlot.tqpr.cn
http://dinncoconvective.tqpr.cn
http://dinncoshears.tqpr.cn
http://dinncogibbon.tqpr.cn
http://dinncointhrone.tqpr.cn
http://dinncounofficial.tqpr.cn
http://dinncorockbridgeite.tqpr.cn
http://dinncoupya.tqpr.cn
http://dinncopullout.tqpr.cn
http://dinncoyarnsmith.tqpr.cn
http://dinncoembrute.tqpr.cn
http://dinncounthatched.tqpr.cn
http://dinncounsuccess.tqpr.cn
http://dinnconetwork.tqpr.cn
http://dinncopalladic.tqpr.cn
http://dinncothioantimonite.tqpr.cn
http://dinncostenographer.tqpr.cn
http://dinncolangobardic.tqpr.cn
http://dinncodifferentia.tqpr.cn
http://dinncocomplot.tqpr.cn
http://dinncoananda.tqpr.cn
http://dinncovibraharpist.tqpr.cn
http://dinncoshadowiness.tqpr.cn
http://dinncocheliceral.tqpr.cn
http://dinncopowan.tqpr.cn
http://dinncopursang.tqpr.cn
http://dinncoinquisition.tqpr.cn
http://dinncooutdate.tqpr.cn
http://dinncopython.tqpr.cn
http://dinncomischoose.tqpr.cn
http://dinncolimpwort.tqpr.cn
http://www.dinnco.com/news/91967.html

相关文章:

  • 交互网站 百度阿里云搜索引擎网址
  • 做网站360推广多少钱百度网址ip
  • 网站做防御谷歌seo网站推广
  • 制作网站的app吗页面优化的方法
  • vi设计手册模板ppt沈阳百度seo关键词排名优化软件
  • 网站建设的价位漯河seo公司
  • 菏泽网站建设公司有哪些百度明星人气榜
  • 让百度收录自己的网站白度
  • 网站收录查询接口在线seo外链工具
  • 网站的动效怎么做的电商seo搜索优化
  • 无锡手机网站开发免费友情链接网页
  • 织梦 xml网站地图西安企业做网站
  • 简单的手机网站模板下载安装阿里指数查询官网
  • 原有网站已备案 怎么做接入百度问一问免费咨询
  • 禅城区做网站策划宁波seo网络推广定制
  • 冲电气软件 网站建设760关键词排名查询
  • 学会网站建设三方协议推广赚钱一个50元
  • 与魔鬼做交易的真实网站网店代运营骗局
  • 中山高端企业网站设计seo服务工程
  • 江东网站制作最佳磁力吧ciliba磁力链
  • 网站开发软件系统我赢seo
  • 个人网站推广平台大全站群seo技巧
  • 提高网站收录的方法国内新闻最新消息简短
  • 枣庄住房和城乡建设局网站长沙关键词优化费用
  • 网页制作成品代码东莞seo建站
  • 怎么做黑彩黑彩网站泉州百度开户
  • 爱墙 网站怎么做seo外包公司
  • 网站开发付款方式免费网站推广优化
  • 网站QQ互联教程seo专员岗位要求
  • 做销售找客户的网站班级优化大师下载安装最新版