[关闭]
@XQF 2018-03-07T22:53:57.000000Z 字数 395 阅读 716

排序----冒泡排序

数据结构与算法


邻居好好说话:

  1. public class Solution {
  2. public int[] bubbleSort(int[] nums) {
  3. for (int i = 0; i < nums.length; i++) {
  4. for (int j = 0; j < nums.length - i - 1; j++) {
  5. if (nums[j] > nums[j + 1]) {
  6. int temp = nums[j];
  7. nums[j] = nums[j + 1];
  8. nums[j + 1] = temp;
  9. }
  10. }
  11. }
  12. return nums;
  13. }
  14. public static void main(String[] args) {
  15. Solution solution = new Solution();
  16. int[] nums = {1, 2, 55, 6, 3, 2, 4, 5, 6, 8, 9, 0};
  17. System.out.println(Arrays.toString(solution.bubbleSort(nums)));
  18. }
  19. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注