-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubbleSort.java
More file actions
24 lines (22 loc) · 590 Bytes
/
BubbleSort.java
File metadata and controls
24 lines (22 loc) · 590 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package com.bzp.algorithm;
import java.util.Arrays;
/**
* by bzp
* desc:冒泡排序算法实现。
* 时间复杂度为:O(n^2) 空间复杂度为:O(1)
*/
public class BubbleSort {
public int[] sortfun(int[] sortarr){
int n = sortarr.length;
for(int i = 1;i < n;i++){
for(int j = 0;j < n-i;j++){
if(sortarr[j] > sortarr[j+1]){
int temp = sortarr[j];
sortarr[j] = sortarr[j+1];
sortarr[j+1] = temp;
}
}
}
return sortarr;
}
}