Sort within-bubble sort

Source: Internet
Author: User

Algorithm idea: From the back to the adjacent elements of the 22 comparison exchange, each trip will be the smallest or largest element "float" to the end, eventually achieve a completely orderly

 PackageSort;ImportFangwei. Directsort; Public classbubblesort{ Public Static voidMain (string[] args) {int[] A =New int[] {20, 30, 90, 40, 70, 110, 60, 10, 100, 50, 80, 1, 2 }; Bubblesort Bubblesort=NewBubblesort (); Bubblesort.        Sort (a);        ;  for(intt:a) System.out.println (t); }            voidExchangedata (int[] datas,intIndex1,intindex2) {DATAS[INDEX1]= datas[index1]+Datas[index2]; DATAS[INDEX2]= datas[index1]-Datas[index2]; DATAS[INDEX1]= datas[index1]-Datas[index2]; }     Public voidSort (int[] Array) {        intn=Array.Length;  for(inti = 0; i < n-1; i++)//Number of exchanges: n-1,n-2,n-3 ..... 1 times, note that direct insertion is 1,2,3,4, ... N-1 Times,        {             for(intj = 0; J<n-i-1; J + +)            {                if(array[j]>array[j+1]) Exchangedata (Array, J, J+1); }        }    }}

Sort within-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: 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.