1. Purpose
These days to look at other people's algorithmic blog, found that some people's code is wrong. And the search engine ranked very high, misleading a lot of people, so they wrote this blog.
2. Algorithm Description
Binary selection sorting is an improvement on simple selection sorting. The simple choice of sorting is to select the smallest value from the data exchange with the first position, then select the smallest value in the rest of the data and the second position of the data exchange and so on. The two-dollar selection sort is the maximum and minimum value of each selected data, respectively, and the first and last exchange.
3. Code
/**
* time:2017 Year December 28
* Author:triomphe
*/
#include <stdio.h><stdlib.h>
Binary selection sort void twoselectsort (int a[], int n) { int
for (i=0;i<n/2;i++) {
min=i,max=i; The minimum and maximum values are first pointed to the first number that is not sorted. For (j=i+1;j<n-i;j++) { if (a[j]<a[min]) {min=J; continue;} if (a[j]>A[max]) {max=J;}}
Set Mintmp,maxtmp to temporarily store data, and some blogs use a variable to exchange maximum and minimum values for errors. mintmp=a[min]; maxtmp=A[max]; a[min]=a[i]; a[max]=a[n-i-1]; a[i]=mintmp; a[n-i-1]= maxtmp; PrintArray (A,n); printf ("\ n");}} Output array void printArray (int a[],int n) {int i; for (i=0;i<n;i++) {printf ("%d", A[i]);}}
intMain () {
Array of definitionsintdata[]={275,322, A,2, at, A, +,123, A,3, About, the, About, A,1232,3, 14, $, A, A, One, -, About}; intn =sizeof(data)/sizeof(data[0]); Twoselectsort (Data,n); PrintArray (Data,n); return 0;}
4. Final results
Binary selection sort