选择排序
1 void Select(int *a,int n) 2 { 3 for (int i = 0; i < n; i++) 4 { 5 int lowindex = i; 6 for (int j = i + 1; j < n; j++) 7 { 8 if (a[j] < a[lowindex]) 9 lowindex = j; 10 swap(&a[i], &a[lowindex]); 11 } 12 } 13 }
冒泡排序
1 void Bubblesort(int *a,int n) 2 { 3 for(int i=0;i < n; i++) 4 if(a[j] >a[j+1]) 5 swap(&a[i], &a[lowindex]); 6 }
插入排序
1 void insertsort() 2 { 3 int i ,j; 4 int temp; 5 for (i = 1; i < n; i++) 6 { 7 temp = a[i]; 8 for (j = i; j > 0 && temp < a[j - 1]; j--) 9 { 10 a[j] = a[j - 1]; 11 } 12 a[j] = temp; 13 } 14 }