Java array One dimension array bubble sort algorithm

Source: Internet
Author: User

http://www.verejava.com/?id=16992682424030

 /* Using the bubbling algorithm: arrays the score from small to large sort output idea: The first order of 1. Compares the n elements of an array from the first element to the following elements 2. If the previous data is larger than the data behind it, the two switching positions until the loop is complete, that    The largest data in the array will be in the last position of the array. The first order of 3.    And so on, the remaining unsorted n-i elements are again similar to the process again, so that until the end of the loop n times, the elements in the array are ordered from small to large.  Note: Just go through n-1 sort */public class bubblesort{public static void sort (int[] arrays) {//First loop control n-1 reorder for (int i=0;i<arrays.length-1;i++) {//second loop controls the number of elements to compare each time n-1 for (int j=0;j<arrays.length-i-1;j+                    +) {if (arrays[j]>arrays[j+1]) {int flag=arrays[j];                    ARRAYS[J]=ARRAYS[J+1];                Arrays[j+1]=flag; }}}} public static void Main (string[] args) {//one-dimensional array definition and initialization int[] scores={90,7                0,50,80,60,85};        Sort (scores);        Output sorted scores for (int i=0;i<scores.length;i++) {System.out.print (scores[i]+ ","); }    }}

http://www.verejava.com/?id=16992682424030

Java array One dimension array bubble sort algorithm

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.