Data structure C language implementation selection sorting

Source: Internet
Author: User

Introduction to choosing a sort

Select the sort is the outer layer for the n-1, the inner layers of n-1, each trip to select the largest or smallest data on the front.

Second, code implementation

#include <stdio.h>/* Two data exchange/void Swap (int* Ina, int* Inb) {int temp = *ina;
    *ina = *INB;
*INB = temp;
    /* * Function function: Select the sort, the data from small to large sorting * parameter explanation: InArray input Array * Inlen input array length * * int selectsort (int* inarray,int inlen) {

    int i = 0,j = 0;

    if (InArray = NULL) return 1;
        /* Outer loop/for (i = 0; i < InLen-1 i++) {/* Inner loop */for (j = i + 1; j < Inlen; J +) {/* always guarantee every time/if (Inarray[i] > Inarray[j]) {Swap (&inarray[i],&
            AMP;INARRAY[J]);
}} return 0;
    int main () {int a[] = {49,38,65,97,76,13,27};

    int index = 0;

    int len = sizeof (a)/sizeof (int);
    /* First traverse the elements of the array to print/for (index = 0; index < len; index++) {printf ("%d", A[index]);

    printf ("\ n");

    /* Call the Select Sort function */selectsort (A,len); /* Iterate through the elements of the array * * for (index = 0; index < len; index++) {printf ("%d ", A[index]);



    printf ("\ n");
return 0;


 }

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.