堆排序算法的实现 (冒泡排序)

方法一:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace ConsoleApplication3
{class Program{static void Main(string[] args){List<int> seqlist = new List<int> { 42, 20,17, 27,13,8,17,48};HeadOrder(seqlist, 0, seqlist.Count - 1);}public void BubbleSort(List<int> sqList){}public static void CreadHeap(List<int> seqList, int low, int high){            int k;int j=0;int temp = 0;for (int i = high / 2; i >= low; i--){k = i;temp = seqList[i];j = 2 * k + 1;               while (j <= high){                  if (j < high && j + 1 <= high && seqList[j] < seqList[j + 1]){j++;}if (temp < seqList[j]){seqList[k] = seqList[j];                                          k = j;j = 2 * k + 1;}else{j = high + 1;}}seqList[k] = temp;}}public static void HeadOrder(List<int> seqlist, int low, int high){if (high <= low){return;}int temp = 0;CreadHeap(seqlist, 0, high);for (int i = seqlist.Count - 1; i > low; i--){temp = seqlist[0];seqlist[0] = seqlist[i];seqlist[i] = temp;CreadHeap(seqlist, 0, i-1);               }}}
}

 方法二:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace ConsoleApplication3
{class Program{static void Main(string[] args){List<int> seqlist = new List<int> { 42, 20,17, 27,13,8,17,48};HeadOrder(seqlist, 0, seqlist.Count - 1);}public void BubbleSort(List<int> sqList){int tmp = 0;for (int i = 0; i < sqList.Count -1; ++i){for (int j = i +1; j<sqList.Count; j++){if (sqList[i] < sqList[j]){tmp = sqList[i];sqList[i] = sqList[j];sqList[j] = tmp;}}}}public static void CreadHeap(List<int> seqList, int low, int high){int k;int j = 0;int temp = 0;for (int i = high / 2; i >= low; i--){k = i;j = 2 * k + 1;while (j <= high){temp = seqList[k];if (j < high&& j + 1 <= high&& seqList[j] < seqList[j + 1]){j++;}if (temp < seqList[j]){seqList[k] = seqList[j];seqList[j] = temp;k = j;j = 2 * k + 1;}else{j = high + 1;}}}}public static void HeadOrder(List<int> seqlist, int low, int high){if (high <= low){return;}int i = low;int temp = 0;CreadHeap(seqlist, 0, high);temp = seqlist[0];seqlist[0] = seqlist[high];seqlist[high] = temp;HeadOrder(seqlist, i, high - 1);}}
}

 

 

转载于:https://www.cnblogs.com/Jessy/p/3469246.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/408254.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

角色转变

11月4日花了整整一天的时间和航发锦绣家园签订了不平等“条约”时&#xff0c;开始我的角色开始准备转化为负债者&#xff0c;在之后的10年间将每月偿还给工商银行&#xffe5;849。买房&#xff0c;你说还能是什么呢&#xff1f;这个我这个年龄段的头等大事。婚姻&#xff1f;…

a href='?out=login'是什么意思

<a href?outlogin>退出</a>前面加上问号&#xff1f;就是GET方式传递outlogin是要传递的数据点这个链接就可以执行接下来通过$_GET["out"]接收这个时候$_GET["out"]的值就是login<a href?outlogin>退出</a>就是向本页传递数据要…

常用js函数

/**//*------------------------------------------------------------ dateDlg(inputid,initDate,startYear,endYear) 弹出时间窗口 compareDate(end,s) 与当前时间比较 compareTwoDate(startDate,endDate,s) 比较两个时间 isNumber(text…

读取xml文件转成ListT对象的两种方法(附源码)

读取xml文件转成List<T>对象的两种方法&#xff08;附源码&#xff09;读取xml文件&#xff0c;是项目中经常要用到的&#xff0c;所以就总结一下&#xff0c;最近项目中用到的读取xml文件并且转成List<T>对象的方法&#xff0c;加上自己知道的另一种实现方法。 就…

委托的运用

下面这篇代码展示了委托的运用,非常精彩,代码版权归"microsoft"所有. 1//版权所有 (C) 2000 Microsoft Corporation。保留所有权利。23//bookstore.cs4usingSystem;56//处理书店的一组类:7namespaceBookstore 8{ 9 using System.Collections; 10 11 // 描述图书…

visual studio enter键代码自动补全

将resharper插件中的设置内容改成这个就可以enter键自动补全了

使用air进行移动app开发常见功能和问题(二)

1、 Air如何判断android、ios 平台网络连接状态&#xff1f; Android&#xff0c;使用as3原生api&#xff1a; [javascript] view plaincopy if(NetworkInfo.isSupported)//只有android支持 NetworkInfo.networkInfo.addEventListener(Event.NETWORK_CHANG…

虚拟内存相关原理

内存管理1.虚拟内存2.内存分段3.内存分页多级页表TLB1.虚拟内存 众所周知:单片机是没有操作系统的,所以单片机的CPU是直接操作内存的物理地址(physical address,PA) 在这种情况下,程序内存中是无法同时运行多个程序。例如第一个程序在10位置的位置存放立一个数值&#xff0c;…

Team Up!用Visual Studio 2005 Team System组织所有的装备 --作者:Chris Menage

[摘要]本文基于Visual Studio 2005 Team System CTP&#xff0c;为您介绍在软件开发周期中中的开发进程、团队支持、工作项跟踪、单元和装载测试及其他。 软件开发通常被认为是个很困难的过程。前人已经通过组织无数次地学习和编著大量的书籍来阐述如何改进开发应用程序的流程…

贪心算法(leetcode分类解题,C++代码详细注释)

贪心算法前言455.分发饼干135.分发糖果435.无重叠区间605.种花问题452.用最小数量的箭引爆气球763.划分字母区间122. 买卖股票的最佳时机 II376. 摆动序列53. 最大子序和前言 贪心算法或贪心思想采用贪心的策略&#xff0c;保证每次操作都是局部最优的&#xff0c;从而使最后得…

互联网日志的种类、存储和计算

最近几年&#xff0c;经常听到数据挖掘这个词。不过&#xff0c;我仔细看了下&#xff0c;发现这个词还是挺模糊的。挖掘这个词&#xff0c;应该指从数据中发现有价值的信息。比如从搜索词中&#xff0c;发现网民的关注点&#xff0c;进而指导广告投放、产品推荐&#xff0c;生…

[转]2006年十二星座运程 目录

白羊座2006年运程 金牛座2006年运程 双子座2006年运程 巨蟹座2006年运程 狮子座2006年运程 处女座2006年运程 天秤座2006年运程 天蝎座2006年运程 射手座2006年运程 摩羯座2006年运程 水瓶座2006年运程 双鱼座2006年运程作者Blog&#xff1a;http://blog.csdn.net/cndg…

双指针法(leetcode分类解题,C++代码详细注释)

双指针法前言167.两数之和 II - 输入有序数组88.合并两个有序数组142. 环形链表 II633.平方数之和680. 验证回文字符串 Ⅱ27. 移除元素344. 反转字符串剑指 Offer 05. 替换空格151. 翻转字符串里的单词206.反转链表125. 验证回文串19. 删除链表的倒数第 N 个结点面试题 02.02. …