HeapSort的C#实现
来源:互联网 发布:容错手机缩水软件 编辑:程序博客网 时间:2024/05/22 13:41
把算法导论第六章的堆排序用C#实现了一下。 把MaxHeapify用迭代实现了。发现几个问题:
第一呢,算法导论中假设内部数组是从1开始的,结果左右结点的算法和从0开始的数组实际上是不同的。
第二呢,在改迭代的时候,粗心把循环变量写错了。结果调了很久,郁闷死。
并且加入优先级队列的功能,包括Maximum, ExtractMax, IncreaseKey, Insert, Delete子过程
下面是实现的代码:
第一呢,算法导论中假设内部数组是从1开始的,结果左右结点的算法和从0开始的数组实际上是不同的。
第二呢,在改迭代的时候,粗心把循环变量写错了。结果调了很久,郁闷死。
并且加入优先级队列的功能,包括Maximum, ExtractMax, IncreaseKey, Insert, Delete子过程
下面是实现的代码:
namespace FengChen.Practices
{
public class Chapter6
{
public class MaxHeap
{
private Int32[] m_Array;
private Int32 m_Size;
heap tree node navigation
public Int32 Size { get { return m_Size; } }
public MaxHeap(Int32 size)
{
m_Array = new Int32[size];
m_Size = Size;
BuildMaxHeap();
}
public MaxHeap(Int32[] inputArray)
{
if (inputArray == null)
throw new ArgumentNullException("inputArray", "The input Array cannot be null!");
m_Array = inputArray;
m_Size = inputArray.Length;
BuildMaxHeap();
}
public String Show()
{
// List the current heap elements
return Common.ListTheArray(m_Array);
}
6.2 Maintaining the heap property
6.3 Building a max heap
Veriry a max heap
6.4 The heapsort algorithm(Sort to non-increasing order)
6.5 Priority queues
}
}
}
{
public class Chapter6
{
public class MaxHeap
{
private Int32[] m_Array;
private Int32 m_Size;
heap tree node navigation
public Int32 Size { get { return m_Size; } }
public MaxHeap(Int32 size)
{
m_Array = new Int32[size];
m_Size = Size;
BuildMaxHeap();
}
public MaxHeap(Int32[] inputArray)
{
if (inputArray == null)
throw new ArgumentNullException("inputArray", "The input Array cannot be null!");
m_Array = inputArray;
m_Size = inputArray.Length;
BuildMaxHeap();
}
public String Show()
{
// List the current heap elements
return Common.ListTheArray(m_Array);
}
6.2 Maintaining the heap property
6.3 Building a max heap
Veriry a max heap
6.4 The heapsort algorithm(Sort to non-increasing order)
6.5 Priority queues
}
}
}
- HeapSort的C#实现
- heapsort的实现
- HeapSort的java语言实现
- HeapSort堆排序的理解和实现
- heapsort(堆排序)的代码实现
- 堆排序算法的实现(HeapSort)
- heapsort实现代码
- HeapSort非递归实现
- Heapsort
- Heapsort
- HeapSort
- heapsort
- HeapSort
- HeapSort
- HeapSort
- heapsort
- heapsort
- heapsort
- 抛弃清高,赚钱重要
- 开发项目之分析和设计
- 自已理解的装饰者模式
- 对于刚接触的软件测试行业所提的一些小问题
- Linux常用命令[转]
- HeapSort的C#实现
- C51用IO口模拟SPI
- 模型表示的数据结构 Nonmanifold 和Manifold
- 第九作坊简介
- linux服务器历险之linux有用的技巧
- c#,socket,data boundary,
- 作业3
- JAVA的I/O操作(一)
- 使用memcached进行内存缓存