The basic idea of Bubble Sort is to see the array to be sorted as falling down from above, the records with smaller keywords as lighter, the keywords with larger keywords as heavier, the values of smaller keywords as bubbles in water floating up, and the larger keywords like stones in water sinking, and the sorting ends when all bubbles float to the corresponding position.
Algorithm performance analysis
(1) Time complex element. The total number of times is 3/2(n-1)*n
(2) Space complexity. Only one auxiliary unit is used for space complexity of O(1)
(3) The stability of the algorithm. Bubble sorting is a stable sorting 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 it can help you, and thank you for your support for this website!