stability algorithm: Direct insert Sort, binary insert sort, bubble sort, merge sort
Unstable algorithms: Hill Sort, quick sort, simple select sort, heap sort
Direct Insert Sort (Find final position insertion from the original position in the ordered section successive comparison)
voidInsertsort (Elemtype a[],intN) {intI, J; for(i =2, I <= N; i++) if(A[i].key < A[i-1].key) {a[0] =A[i]; for(j = i-1; a[0].key < A[i].key; --j) A[j+1] =A[j]; A[j+1] = a[0]; }}View Code
Binary Insert Sort
voidInsertsort (Elemtype a[],intN) {intI, J, low, High, mid; for(i =2; I <= N; i++) {a[0] =A[i]; Low=1; High = i-1; while(Low <=High ) {Mid= (low + high)/2; if(A[mid].key > a[0].key) high = mid-1; ElseLow = mid +1; } for(j = i-1; J >= High +1; --j) A[j+1]=A[j]; A[high+1] = a[0]; }}View Code
Hill sort
voidShellsort (Elemtype a[],intN) { for(DK = len/2; DK >=1; DK = DK/2) for(i = DK +1; I <= N; ++i)if(A[i].key < A[i-dk].key) {a[0] =A[i]; for(j = i-dk; J >0&& a[0].key < A[j].key; J-= DK) a[j + DK] =A[j]; A[j+ DK] = a[0]; }}View Code
Bubble sort
Internal sorting algorithm