Simple sorting algorithm design (Java)

Source: Internet
Author: User

A total of eight sorting algorithms, or slowly look at it

1. Simple Sorting algorithm

The simple sort algorithm is to set the pacesetter, compare the numbers one by one, then find the insertion position, insert

 Public Static voidPint[] a) {       for(inti=0;i<a.length;i++) {System.out.print (A[i]+" "); }    }         Public Static voidSorting (int[] a) {        intm =a.length;  for(inti=1;i<m;i++){        if(i==1){            if(a[i]<a[i-1]){                inttemp =A[i]; A[i]= A[i-1]; A[i-1] =temp; }        }Else{         if(a[i]<a[i-1]){            intJ=i-1; intX=a[i];//set X as Pacesetter//A[i]=a[i-1]; //System.out.println (A[j]);              while(x<A[j]) {//Find location, compare size A[j+1]=A[j]; Move backward One J--;                P (a);            System.out.println (); } a[j+1]=x; Insert} }}}

Simple sorting algorithm design (Java)

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.