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

怎么给网站做动图凯里网站建设公司哪家好

怎么给网站做动图,凯里网站建设公司哪家好,中信建设有限责任公司临空经济区,金华市网站建设公司计算机中的堆数据结构 什么是堆 在计算机科学中#xff0c;堆#xff08;Heap#xff09;是一种重要的数据结构#xff0c;它用于在动态分配时存储和组织数据。堆是一块连续的内存区域#xff0c;其中每个存储单元#xff08;通常是字节#xff09;都与另一个存储单元…计算机中的堆数据结构 什么是堆 在计算机科学中堆Heap是一种重要的数据结构它用于在动态分配时存储和组织数据。堆是一块连续的内存区域其中每个存储单元通常是字节都与另一个存储单元紧密相邻。 堆和栈是计算机内存的两种主要部分。其中栈用于存储局部变量和函数调用的信息而堆则用于存储动态分配的变量和数据结构。 堆的特点是可以动态地增加和减少内存而且可以任意分配内存的大小。这意味着你可以在运行时分配内存以存储例如动态数组图形数据结构优先级队列等数据。 堆的好处及适用场景 堆数据结构有许多优点这使得它在许多计算场景中都非常有用。 动态内存分配堆允许我们在运行时动态地分配和释放内存。这意味着我们可以在程序执行的过程中根据需要创建或删除数据。大小不定与栈不同堆的大小不是预先确定的。这意味着我们可以用它来存储大量的数据只要可用的系统内存允许。支持自定义数据类型由于堆是通用的内存分配机制因此可以用它来存储任何类型的数据不仅仅是基本类型。 下面是一些适用的场景 动态数组堆是创建动态数组例如动态调整大小的数组的理想场所。你可以在运行时根据需要增加或减少数组的大小。优先级队列优先级队列经常使用堆来实现。在这种情况下堆的特性允许我们有效地插入和删除元素以及在O(1)时间内查找最大或最小元素。动态链接列表在动态链接列表中我们需要在运行时创建和删除节点。这也需要使用堆内存。图形和树结构图形和树结构通常使用堆来实现因为这些数据结构需要在运行时动态地添加和删除节点。 C代码实现一个堆并测试 以下是一个简单的最小堆的C实现。注意这个例子只是为了教育目的并没有包含一些关键的功能比如防止溢出或检查是否溢出。 然后我们可以继续实现其他堆操作例如删除元素查找最小元素等。以下是一个更完整的堆实现包括上述缺失的操作 #include iostream #include vector #include stdexcept // for std::out_of_range class MinHeap { private: std::vectorint data; // underlying data structure int parent(int i) { return (i - 1) / 2; } // parent index int leftChild(int i) { return 2 * i 1; } // left child index int rightChild(int i) { return 2 * i 2; } // right child index void siftUp(int i) { // sift element i up to its proper place while (i 0 data[parent(i)] data[i]) { std::swap(data[parent(i)], data[i]); i parent(i); } } void siftDown(int i) { // sift element i down to its proper place int minIndex i; // index of current minimum element int l leftChild(i); // left child index if (l data.size() data[l] data[minIndex]) { minIndex l; } int r rightChild(i); // right child index if (r data.size() data[r] data[minIndex]) { minIndex r; } if (i ! minIndex) { // swap i and minIndex if necessary and repeat siftDown on affected subtree std::swap(data[i], data[minIndex]); siftDown(minIndex); } } void siftUpForInsert(int i) { // sift element i up to its proper place after insert for heap property to be maintained while (i 0 data[parent(i)] data[i]) { std::swap(data[parent(i)], data[i]); i parent(i); } } public: void insert(int value) { // insert value into heap and maintain heap order property data.push_back(value); // append value to the end of the vector and remember its index (size - 1) siftUpForInsert(data.size() - 1); // sift up to maintain heap order property (parent is larger than its children) after insert } int extractMin() { // extract the current minimum element from heap and maintain heap order property if (data.empty()) { throw std::out_of_range(Heap is empty); } // heap is empty, so there is no min element throw an exception here to indicate that the situation cannot be handled and the program should stop execution with an error message to user indicating the error situation that occurred here. int minElement data[0]; // store the minimum element in a temporary variable minElement before swapping it with the last element in the vector and deleting it from the vector in the next step (data.pop_back()) as this will change the size of the vector and all further indices will shift downwards by one position in memory. std::swap(data[0], data[data.size() - 1]); // swap the first element with the last element in the vector as they will have swapped roles after this step (the last element will become the new first element/minimum element in its new position in memory while the first element will become the last element in its new position in memory after this swap operation) for maintaining the heap property after extract operation. data.pop_back(); // remove the last element from the vector as it has just become unnecessary/redundant/no longer required in memory after the previous swapping step to maintain heap order property as required. As it is removed, all further indices will shift downwards by one position in memory for maintaining the heap property after extract operation. siftDown(0); // sift down the new first element/minimum element to maintain heap order property after extract operation as required. The root/first element is always at index 0 in a heap as shown in all figures above for heap data structure shown above in this code segment also. Heap is a complete binary tree (each node has either two children or no children). Binary tree is a type of tree where each node has}
http://www.hkea.cn/news/14339606/

相关文章:

  • 做兼职一般去哪个网站制作表情包的软件
  • 群晖 做网站服务器百度搜索引擎关键词优化
  • 重庆航运建设发展有限公司 网站天元建设集团有限公司 天眼查
  • 广州网站建设粤icp网站建设需要精通什么知识
  • 有edi证书可以做网站运营么石家庄做外贸的网站建设
  • 上海城市建设大学网站html个人网页制作模板
  • 怎么做租号网站企业在线注册
  • 大连项目备案网站wordpress active
  • 腾度网站建设专家作品展示的网站
  • 微网站开发难度建设部资质升级网站
  • 免费的培训网站建设广州网站推广找谁
  • 有专门做英文字幕的网站吗企业查找
  • 赣州网站制作找哪家好北京工程信息网官网
  • 网站开发公司规章制度重庆城乡和住房建设信息网
  • 食品网站建设规划书wordpress 会员分类
  • 深州市住房保障和城乡建设局网站安徽省住房与城乡建设厅网站
  • 莒县网站建设公司网站由哪些部分组成
  • 提升网站的访问速度做cg的网站
  • 万维网网站域名续费iview可以做门户网站吗
  • 黄山网站seo用什么程序做视频网站
  • 做胃肠医院网站怎么在网上推广广告
  • 电脑版 做网站尺寸网站建设网站维护的具体内容是什么
  • 做衣服外贸用什么网站好wps演示做的和网站导航
  • 电商网站建设 问题 心得体会阿里巴巴做网站的电话号码
  • 网站开发用的框架前端海报设计 网站
  • 网站页面设计公司推荐黑龙江建设网ca锁费用
  • 电子商务网站推广的目的买机票便宜网站建设
  • 郑州做网站推广的公司哪家好福建省建筑施工企业信用评价系统
  • 网站开发与设计结课大作业官方网站建设状况
  • 企业官网设计图广州优化排名推广