C++ implementation of order sorting algorithm simple sample code

  • 2020-04-02 02:34:43
  • OfStack

This example tells about the most direct sequence sorting method VC++ sample code, remember before school when this is the computer must test, and in the sorting algorithm, sequence sorting seems to be the most simple, is the easiest to master. Now let's go over it again!

The specific code is as follows:


//order
void InsertSort(int r[], int n){ 
for (int i=2; i<n; i++){ 
r[0]=r[i]; //Set the sentry
for (int j=i-1; r[0]<r[j]; j--) //Find the insertion position
r[j+1]=r[j]; //Records backwards
r[j+1]=r[0]; 
}
for(int k=1;k<n;k++)
cout<<r[k]<<" "; 
cout<<"n";
}

Related articles: