it repeatedly visited the sequence to be sorted, two elements at a time, assuming they were in the wrong order to swap them over. The work of visiting the series is repeated until there is no need to exchange, that is to say, the sequence is sorted out.
The bubbling sort algorithm works such as the following: (from back to forward)
The more adjacent elements. Assuming that the first one is larger than the second one, swap them both.
Do the same work for each pair of adjacent elements, from the first pair to the end of the beginning. At this point, the last element should be the maximum number.
Repeat the above steps for all elements, except for the last one.
Keep repeating the above steps each time for fewer elements, until no matter what pair of numbers you need to compare.
public static void Bubblesort () {int a[] = {28,27,26,25,24,23,22,21,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1}; int temp = 0;for (int i = 0; i < a.length-1; i++) {for (int j = 0; J < a.length-1-I; + j) {if (A[j] > a[j + 1]) {temp = A[j];a[j] = a[j + 1];a[j + 1] = temp;}} for (int n = 0; n < a.length; n++) {System.out.print (a[n]+ ",");} System.out.println ();} for (int n = 0; n < a.length; n++) {System.out.print (a[n]+ ",");}}
Sort-----bubble Sort