Data structure has been reviewed recently and felt that even the scientific point of C to be lost, spent a little time to achieve some sort count a bit, talk to encourage each other.

Direct Insertion Sort:

void insertsort(int *q)/* Insertion sort */ { int i,j,k; for(i=2;i<LENGTH;i++) { q[0]=q[i];/* The first unit acts as a sort of Sentinel, does not participate in */ j=i-1; while(q[0]<q[j])/* Find the right insert location */ { q[j+1]=q[j]; j--; } q[j+1]=q[0]; printf("\n--------------------------------------\n");/* Print each trip for sorting results */ for(k=1;k<LENGTH;k++) { printf("%d ",q[k]); } } }

Binary insertion sort:

void binaryInsertSort(int *q)/* Binary insertion sort */ { int mid,low,high; int i,j; for(i=2;i<LENGTH;i++) { q[0]=q[i]; low=1; high=i-1; while(low<=high)/* Find to be inserted */ { mid=(low+high)/2; if(q[0]<=q[mid]) high=mid-1; else low=mid+1; } for(j=i-1;j>=high+1;j--) q[j+1]=q[j]; q[high+1]=q[0]; printf("\n--------------------------------------\n");/* Print each trip for sorting results */ for(k=1;k<LENGTH;k++) { printf("%d ",q[k]); } } } }

Bubble Sort:

void bubbleSort(int*q)/* Simple bubble sort */ { int i,j; int temp;/* Exchange mediator */ for(i=1;i<LENGTH;i++) { for(j=LENGTH-i;j>=i;j--) { if(q[j]<q[j-1]) { temp=q[j]; q[j]=q[j-1]; q[j-1]=temp; } } } }

Simple Selection Sort:

void selectSort(int*q)/* Select sort */ { int i,j; int k;// Indicates that each time you find the minimum value of the location for(i=1;i<LENGTH;i++) { k=i; for(j=i;j<LENGTH;j++)/* Find current interval the minimum ' */ { if(q[j]<q[k]) k=j; } q[0]=q[k]; q[k]=q[i]; q[i]=q[0]; } }

Test the main function:

int main() { int a[LENGTH]; int i,j; int *p; printf("please input 10 number:\n"); for(i=1;i<LENGTH;i++)/* Enter 10 digit */ { scanf("%d",&a[i]); } printf("the number you have input is:--------------------------\n"); for(j=1;j<LENGTH;j++) { printf("%d",a[j]); printf(" "); } p=a; insertSort(p);/* According to the need to call you want to test sorting function */ printf("\n----------------------insertsort result------------------\n"); for(j=1;j<LENGTH;j++) { printf("%d",a[j]); printf(" "); } /*binaryInsertSort(p); printf("\n----------------------binaryinsertsort result------------------\n"); for(j=1;j<LENGTH;j++) { printf("%d",a[j]); printf(" "); }*/ /*bubbleSort(p); printf("\n----------------------bubblesort result------------------------\n"); for(j=1;j<LENGTH;j++) { printf("%d",a[j]); printf(" "); }*/ /*selectSort(p); printf("\n----------------------selectsort result------------------------\n"); for(j=1;j<LENGTH;j++) { printf("%d",a[j]); printf(" "); }*/ return 0; }

The first part to be written here, the second part includes Hill sort (narrow increments), quick sort, merge sort, heap sort, radix sort, paste a few days out.