<17> "Mastering" bubble Sort Code Implementation + "Mastering" Selection sorting code implementation

Source: Internet
Author: User

#include <stdio.h>voidMaopao (intArr[],intLen) {    inttemp; //Double Loop     for(intI=0; i<len-1; i++){            //because I's the value of each change once, ran a trip, according to bubbling thought//There's a number that's already sunk.//There is no need to compare with the already ordered data.//j<len-1-i; So j<len-1 can also, but more run will         for(intj=0; j<len-1-I.; J + +) {                        if(arr[j]>arr[j+1]) {                //values for interchange a[j] and a[j+1]//Add or Subtract xor temptemp =Arr[j]; ARR[J]= arr[j+1]; Arr[j+1] =temp; }        }        }}intMainintargcConst Char*argv[]) {        inta[Ten]={1, $, at, $, A, the, +,4,388, the}; //A[0] 1//&a[0] Address//before sorting     for(intI=0; i<Ten; i++) {printf ("%d\t", A[i]); } printf ("\ n"); //to sortMaopao (A,Ten);//the numbers are already in order.//iterating through an array     for(intI=0; i<Ten; i++) {printf ("%d\t", A[i]); }        return 0;}

"Mastering" Select Sort Code Implementation

#include <stdio.h>/** * Select sort*/voidSelectsort (intArr[],intLen) {    //write a double loop//    inttemp;  for(intI=0; i<len-1; i++) {             for(intj=i+1; j<len; J + +) {                    //basis of the Exchange//            if(arr[i]>Arr[j]) {                //allow Arr[i] and arr[j] to be exchangedtemp =Arr[i]; Arr[i]=Arr[j]; ARR[J]=temp; }                    }            }}intMainintargcConst Char*argv[]) {        //define an array    inta[Ten]={ at, A,4, the, -, -, +, $,3, -}; //Purpose SortSelectsort (A,Ten); //traversing an output array     for(intI=0; i<Ten; i++) {printf ("%d\t", A[i]); }            return 0;}
3    4     a     -     +     at     -     $     the     -    

<17> "Mastering" bubble Sort Code Implementation + "Mastering" Selection sorting code implementation

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.