package com.zerroi.leetcode.sort; public class BubbleSort { public static void main(String[] args) { Bubble bubble = new Bubble(); int[] res = bubble.bubble(new int[]{2, 1, 9, 3, 10}); for (int item : res) { System.out.println("item = " + item); } } } class Bubble { public int[] bubble(int[] nums) { for (int i = 0; i < nums.length - 1; i++) { for (int j = 0; j < nums.length - i - 1; j++) { int temp; if (nums[j] > nums[j + 1]) { temp = nums[j]; nums[j] = nums[j + 1]; nums[j + 1] = temp; } } } return nums; } }