标签:
留着给自己用吧...
public class FanXingHelper<T> where T:IComparable { /// <summary> /// 冒泡排序算法 /// </summary> /// <param name="array"></param> public T[] MaoPao(T[] array) { int length = array.Length; for (int i = 0; i <= length-2; i++) { for (int j = length-1; j>=1 ; j--) { if (array[j].CompareTo(array[j-1])<0) { T temp = array[j]; array[j] = array[j - 1]; array[j - 1] = temp; } } } return array; } /// <summary> /// 直接插入排序 /// </summary> /// <param name="array"></param> /// <returns></returns> public T[] ZhiJieChaRu(T[] array) { int length = array.Length; for (int i = 1; i < length-1; i++) { int j = i; while (j>=1&&array[j].CompareTo(array[j-1])>0) { T temp = array[j]; array[j] = array[j - 1]; array[j - 1] = temp; j--; } } return array; } /// <summary> /// 选择排序 /// </summary> /// <param name="array"></param> /// <returns></returns> public T[] XuanZhePaiXu(T[] array) { int length = array.Length; for (int i = 0; i <= length-2; i++) { int index = i; for (int j = length-1; j >i; j--) { if (array[j].CompareTo(array[index])<0) { index = j; } T temp = array[i]; array[i] = array[index]; array[index] = temp; } } return array; } /// <summary> /// 希尔排序算法 /// </summary> /// <param name="array"></param> /// <returns></returns> public T[] XiErPaiXu(T[] array) { int length = array.Length; for (int i = length/2;i>0; i=i/2) { for (int j = i; j < i; j++) { if (array[j].CompareTo(array[j-i])>0) { T temp = array[j]; int key = j - i; while (key >= 0 && array[key].CompareTo(temp) > 0) { array[key + i] = array[key]; key -= i; } array[key + i] = temp; } } } return array; } }
如果有错希望能指出来...谢谢
这个主要是看了.net之美突发奇想所以写的这个东西
参考:
http://www.cnblogs.com/JimmyZhang/category/128644.html
标签:
原文地址:http://www.cnblogs.com/fleas/p/4201088.html