C#堆排序实现方法
2015-04-02 10:38
896 查看
本文实例讲述了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#程序设计有所帮助。
您可能感兴趣的文章:
相关文章推荐
- Delphi中实现文件拷贝的三种方法
- 用VC 6.0实现串行通信的三种方法
- 在WEB项目中多维下拉菜单的实现技巧和方法
- 进程间的通讯实现(IPC)的11种方法
- 简单的在线升级的实现方法
- PowerBuilder中实现数据窗口打印预览通用方法
- 在BCB中把主菜单放到工具栏里后,实现自定义快捷键的方法
- 软件登录的几种实现方法
- asp中利用数组实现数据库记录的批量录入方法
- PHP实现文件上传的一种好方法
- 在WIN95中实现文件拷贝的编程方法
- WIN下动态注册码实现方法
- Delphi系列谈之:Delphi中的静态属性及静态方法的实现
- ATL实现Connection Point的一种简单的方法
- 如何在Java中实现远程方法调用
- 在 Windows 中实现 Java 本地方法
- php gzip压缩输出的实现方法
- 两种Delphi实现Singleton模式方法
- HTML中树的实现方法
- Java 的JDBC 数据库连接池实现方法