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 );}}}