Bubble sort (Bubble sort) is a simpler sort algorithm in the field of computer science. It repeatedly visited the sequence to sort, comparing two elements at a time, and swapping them out if they were wrong in the order. The work of the sequence of visits is repeated until no more need to be exchanged, that is, the sequence is sorted. The name of the algorithm is because the larger the element will slowly "float" to the top of the sequence, hence the name.
//bubble sort from small to large int[] A =New int[]{23,45,67,12,97,78,8,36}; System.out.print ("Raw Data"); for(intt:a) {System.out.print (t+ " "); } System.out.println (); //Number of Cycles for(intj=0; J<a.length-1; J + +){ //compare loops before and after for(inti = 0; i< a.length-1-j; i++) { //Compare the size order of the elements before and after if(a[i]>a[i+1]) { //Temporary storage intb =A[i]; A[i]=a[i+1]; A[i+1]=b; }} System.out.print (J+1 + "secondary cycle"); for(intt:a) {System.out.print (t+ " "); } System.out.println (); }
Bubble Method Sort