C#堆排序实现方法
作者:令狐不聪 时间:2022-03-17 02:48:46
本文实例讲述了C#堆排序实现方法。分享给大家供大家参考。具体如下:
private static void Adjust (int[] list, int i, int m)
{
int Temp = list[i];
int j = i * 2 + 1;
while (j <= m)
{
//more children
if(j < m)
if(list[j] < list[j + 1])
j = j + 1;
//compare roots and the older children
if(Temp < list[j])
{
list[i] = list[j];
i = j;
j = 2 * i + 1;
}
else
{
j = m + 1;
}
}
list [i] = Temp;
}
public static void HeapSort (int[] list)
{
//build the initial heap
for (int i = (list.Length - 1) / 2; i > = 0; i-)
Adjust (list, i, list.Length - 1);
//swap root node and the last heap node
for (int i = list.Length - 1; i > = 1; i-)
{
int Temp = list [0];
list [0] = list [i];
list [i] = Temp;
Adjust (list, 0, i - 1);
}
}
希望本文所述对大家的C#程序设计有所帮助。
标签:C#,堆排序
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java创建和启动线程的两种方式实例分析
2023-12-05 08:26:59
java的各种类型转换全部汇总(推荐)
2022-03-01 01:25:43
C# 使用鼠标点击对Chart控件实现数据提示效果
2023-03-05 14:20:06
![](https://img.aspxhome.com/file/2023/0/104230_0s.webp)
详解Jvm中时区设置方式
2023-12-09 02:59:19
Java中Collections.sort的使用
2022-08-20 04:31:49
![](https://img.aspxhome.com/file/2023/0/90210_0s.png)
Springboot基础学习之初识SpringBoot
2022-08-18 08:48:59
![](https://img.aspxhome.com/file/2023/8/75408_0s.png)
java图片验证码生成教程详解
2021-11-04 13:22:14
![](https://img.aspxhome.com/file/2023/7/60987_0s.jpg)
springcloud 如何解决微服务之间token传递问题
2022-08-27 18:43:48
Java基于Runtime调用外部程序出现阻塞的解决方法
2023-11-09 04:24:23
理解Android中Activity的方法回调
2023-06-27 13:35:36
如何安装java的运行环境IDEA
2022-09-20 10:42:38
![](https://img.aspxhome.com/file/2023/0/64380_0s.png)
将本地jar包安装进入maven仓库(实现方法)
2022-06-18 00:35:54
java求余的技巧汇总
2023-08-06 06:33:16
![](https://img.aspxhome.com/file/2023/8/57898_0s.jpg)
Mybatis SqlSessionFactory与SqlSession详细讲解
2021-12-24 22:42:56
![](https://img.aspxhome.com/file/2023/6/62086_0s.png)
Android开发新手常见的10个误区
2021-07-30 02:14:10
浅析Android Service中实现弹出对话框的坑
2023-04-20 16:17:13
Spring @CrossOrigin 注解原理实现
2022-09-03 10:40:04
![](https://img.aspxhome.com/file/2023/1/71851_0s.png)
Java俄罗斯方块小游戏
2021-12-01 04:36:49
![](https://img.aspxhome.com/file/2023/1/65581_0s.png)
Java静态代理和动态代理总结
2022-01-02 18:49:21
Java实现简易扑克牌游戏的完整实例
2022-10-08 14:09:18
![](https://img.aspxhome.com/file/2023/0/63490_0s.png)