Bubble Sort

 avatar
unknown
java
12 days ago
436 B
3
Indexable
class Solution {
    public int bubbleSort(int[] nums) {
        int i, j, n = nums.length, temp;
        for(i=0;i<n;++i)
        {
            for(j=i+1;j<n;++j)
            {
                if(nums[i]>nums[j])
                {
                    temp = nums[i];
                    nums[i] = nums[j];
                    nums[j] = temp;
                }
            }
        }

        return nums;
    }

}
Editor is loading...
Leave a Comment