-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubbleSort.java
More file actions
53 lines (49 loc) · 1.05 KB
/
BubbleSort.java
File metadata and controls
53 lines (49 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package algorithm.sorting;
/**
* The type Bubble sort.
*/
public class BubbleSort {
/**
* Print.
*
* @param array the array
*/
public static void print(int[] array){
int l = array.length;
System.out.print("Array :: ");
for(int i=0;i<l;i++){
System.out.print(array[i]+" ");
}
System.out.print("\n");
}
/**
* Sort int [ ].
*
* @param array the array
* @return the int [ ]
*/
public static int[] sort(int[] array){
int l = array.length;
for(int i =0;i<l;i++){
for(int j=i;j<l;j++){
if(array[i]>array[j]){
int temp = array[i];
array[i] =array[j];
array[j]=temp;
}
}
}
return array;
}
/**
* Main.
*
* @param args the args
*/
public static void main(String[] args){
int[] arr = {2,4,1,5,3,6,7,8,10,9};
print(arr);
arr=sort(arr);
print(arr);
}
}