The basic idea of bubbling (Bubble sort) is: consider arrays to be sorted from top to bottom, with smaller keywords as lighter, larger keywords as heavier, smaller keyword values as bubbles in the water to float, larger keywords like rocks in the water to sink. , the sort ends when the bubbles are floating in the appropriate position.
Algorithm performance analysis
(1) time complex element. The total must be the number of 3/2 (n-1) *n
(2) The complexity of the space. Only one auxiliary unit with space complexity of O (1)
(3) The stability of the algorithm. Bubble sort is a stable sort algorithm
* *
Kiss_my_love *
2012/8/20 *
bubble sort
**/public
static object[] Bubblesort (Object []sort) {
for (int i=1;i<sort.length;i++) {for
(int j=0;j<sort.length-i;j++) {
if ((integer) sort[j]> (integer) Sort[j+1]) {
Object temp=sort[j];
SORT[J]=SORT[J+1];
Sort[j+1]=temp
}
}} return sort;
}
Thank you for reading this article, I hope to help you, thank you for your support of this site!