JAVA Implementation of Bubble Sorting

Source: Internet
Author: User

Bubble Sorting is the simplest way to sort data. It is mainly applicable when the data volume is small and the data to be sorted is basically ordered.

The basic idea of Bubble Sorting is to sort two adjacent parameters by comparing them at a time, and sort them by nested two for loops. Java implements the following:

Public class bubblesort {// constructor without parameterspublic bubblesort () {}; // constructor with parameterspublic int [] bubblesort (INT [] intarr) {for (INT I = 0; I <intarr. length; I ++) {for (Int J = I + 1; j <intarr. length; j ++) {If (intarr [I]> intarr [J]) {int temp = intarr [I]; intarr [I] = intarr [J]; intarr [J] = temp ;}} return intarr;} public static void main (string [] ARGs) {bubblesort = new bubblesort (); int [] intarr = {5, 6, 9, 2, 4, 3, 8}; int [] intarraftersort = bubblesort. bubblesort (intarr); For (INT arritem: intarraftersort) {system. out. print (arritem );}}}

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.