Select sort and Bubble sort

Source: Internet
Author: User

These are two very similar algorithms, all of which are two nested loops. Before looking online a lot of people will choose sort when bubble sort with, I am afraid later mixed, record.

Select sort

    /** * Select sort * @Title: Getselectsort * @Description: TODO (here is a word describing the effect of this method) * @param @param arr * @pa Ram @return Settings file * @return int[] return type * @throws*/     Public Static int[] Getselectsort (int[] arr) {                 for(inti =0; i < arr.length; i++) {            inttemp =0;  for(intj =0; J < Arr.length; J + +) {                if(Arr[i] <Arr[j]) {Temp=Arr[i]; Arr[i]=Arr[j]; ARR[J]=temp; Continue; }            }        }                returnarr; }


Bubble sort

    /*** Bubble Sort * @Title: Getbubblesort * @Description: TODO (here is a word describing the effect of this method) *@param @paramarr *@param @returnSettings File *@returnint[] return type *@throws     */     Public Static int[] Getbubblesort (int[] arr) {        /*** Outer Loop-1 is because the last number does not compare * memory loop-1 is because prevent array out of bounds * memory loop-I bubbling feature outer City Loop once, has determined a bit value, so the value of this bit does not participate in the next loop * The outer layer is once per cycle, the inner layers are less cyclic once, the number of loops is determined, the memory is sorted*/         for(inti = 0; i < arr.length-1; i++) {            inttemp = 0;  for(intj = 0; J < Arr.length-1-i; J + +) {                if(Arr[j] > arr[j+1]) {temp=Arr[j]; ARR[J]= Arr[j+1]; Arr[j+1] =temp; Continue; }            }        }        returnarr; }

Select sort and Bubble 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.