Code #region 堆排序(第0个数据不能排序) staticprivatevoid Sift(int[] r, int i, int m) { int j; int temp; temp = r[i]; j =2* i; while (j <= m) { if (j < m && r[j] < r[j +1]) { j++; } if (temp < r[j]) { r[i] = r[j]; i = j; j =2* i; } else { break; } } r[i] = temp; }
///<summary> /// 堆排序 ///</summary> ///<param name="r">数据源</param> ///<param name="n">元素个数</param> staticpublicvoid HeapSort(int[] r, int n) { int temp; int i; for (i = n /2; i >=1; i--) { Sift(r, i, n); } for (i = n; i >=2; i--) { temp = r[1]; r[1] = r[i]; r[i] = temp; Sift(r, 1, i -1); } }
#endregion
posted on
2009-04-13 11:39gwazy
阅读(247)
评论(0)
编辑收藏举报