Binary selection sort

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.