The insertion sort is suitable for smaller data volumes, and the higher the degree of sorting, the higher the efficiency, but the less efficient the amount of data that is made up of random numbers. The simple code is as follows #include <stdio.h> void quicksort (int array[],int Last)//ascending order, direct row {int i,j;int temp=0;for (i=1;i<last;i++)//starting from second bit, first bit default {temp=array[i];j=i-1;// The number moves back while ((j>=0) && (array[j]>temp)) {array[j+1]=array[j];//, from the end to the front end///compared to the sorted number, when the last one to be sorted is greater than temp. Move the previous one j--;} There is a number if (j!=i-1) {array[j+1]=temp;};} that is greater than temp; for (i=0;i<last;i++) {printf ("%d", Array[i]);}} void Quicksort (int*array,int N)//directly modified with pointers, with the same contents as above {inti,j;int temp;for (i=1;i<n;i++) {temp=* (array+i); for (j=i;j >0&&* (array+j-1) >temp;j--) {* (array+j) =* (array+j-1);} * (ARRAY+J) =temp;}} void Main () {int a[1000]={0},n,i; scanf ("%d", &n); for (i=0;i<n;i++) scanf ("%d", &a[i]); Quicksort (A,n); If you use the pointer to modify, you need to use this sentence: for (i=0;i<n;i++) printf ("%d", A[i]);}
Algorithmic Learning: inserting sort