时光飞逝~

2013年7月9日

插入排序

摘要: 1 template 2 void InsertSort(T *a, int nCount) 3 { 4 for(int i=1;i=0 && key<a[j];j--) 9 {10 a[j+1] = a[j];11 }12 a[j+1] = key;13 }14 15 }16 int main(int argc, char* argv[])17 {18 int a[] = {4,5,7,3,2,1};19 InsertSort(a,sizeof(a)/sizeof(int));20 ... 阅读全文

posted @ 2013-07-09 23:17 时光飞逝~ 阅读(133) 评论(0) 推荐(0)
冒泡排序

摘要: template void BubbleSort(T *a, int nCount){ T nTemp; for(int i=0;ia[j]) { nTemp = a[i]; a[i] = a[j]; a[j] = nTemp; } } }}template void BubbleSort1(T *a, int nCount){ T nTemp; for(int i=nCount-1;i>0;i--) { for(int j=0;j<i;j++) { if(a[i]<a[j]) { nTemp = a[i]; a[i] = a[j]; ... 阅读全文

posted @ 2013-07-09 00:57 时光飞逝~ 阅读(163) 评论(0) 推荐(0)
快速排序

摘要: template void QuickSort(T *a,int left, int right){ if(left>=right) return; int l = left; int r = right; T pivot = a[left]; while(l!=r) { while(lpivot) r--; a[l] = a[r]; while(l<r && a[l]<pivot) l++; a[r] = a[l]; } a[l] = pivot; QuickSort(... 阅读全文

posted @ 2013-07-09 00:52 时光飞逝~ 阅读(163) 评论(0) 推荐(0)